Skip to content

Commit

Permalink
Servos use regular (non-PWM) pins on MEGA boards. Remove listener whe…
Browse files Browse the repository at this point in the history
…n pin mode set to out.
  • Loading branch information
vickash committed Apr 1, 2013
1 parent 4c1bc25 commit d30e070
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
## 0.11.2 ## 0.11.2


* Make servos work better by using the existing Arduino Servo library. * Make servos work better by using the existing Arduino Servo library.
* Up to 12 servos can be controlled, on digital pins 2-13 only. * Up to 12 servos can be controlled.
* On MEGA boards, servos may be used on pins 22-33 ONLY.
* On other boards, servos may be used on pins 2-13 ONLY.
* Flashing the updated sketch to the board is required. * Flashing the updated sketch to the board is required.


## 0.11.1 ## 0.11.1
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/tx_rx/usb_serial_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module Dino
IO.should_receive(:select).and_return(true) IO.should_receive(:select).and_return(true)


subject.stub(:io).and_return(mock_serial = mock) subject.stub(:io).and_return(mock_serial = mock)
mock_serial.should_receive(:puts).with('a message') mock_serial.should_receive(:syswrite).with('a message')
subject.write('a message') subject.write('a message')
end end
end end
Expand Down
8 changes: 4 additions & 4 deletions src/lib/Dino.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -113,13 +113,13 @@ long Dino::timeSince(long event) {
// CMD = 00 // Pin Mode // CMD = 00 // Pin Mode
void Dino::setMode() { void Dino::setMode() {
if (val == 0) { if (val == 0) {
removeListener();
pinMode(pin, OUTPUT); pinMode(pin, OUTPUT);
#ifdef debug #ifdef debug
Serial.print("Set pin "); Serial.print(pin); Serial.print(" to "); Serial.println("OUTPUT mode"); Serial.print("Set pin "); Serial.print(pin); Serial.print(" to "); Serial.println("OUTPUT mode");
#endif #endif
} }
else { else {
removeListener();
pinMode(pin, INPUT); pinMode(pin, INPUT);
#ifdef debug #ifdef debug
Serial.print("Set pin "); Serial.print(pin); Serial.print(" to "); Serial.println("INPTUT mode"); Serial.print("Set pin "); Serial.print(pin); Serial.print(" to "); Serial.println("INPTUT mode");
Expand Down Expand Up @@ -201,13 +201,13 @@ void Dino::servoToggle() {
#ifdef debug #ifdef debug
Serial.print("Detaching servo"); Serial.print(" on pin "); Serial.println(pin); Serial.print("Detaching servo"); Serial.print(" on pin "); Serial.println(pin);
#endif #endif
servos[pin - 2].detach(); servos[pin - SERVO_OFFSET].detach();
} }
else { else {
#ifdef debug #ifdef debug
Serial.print("Attaching servo"); Serial.print(" on pin "); Serial.println(pin); Serial.print("Attaching servo"); Serial.print(" on pin "); Serial.println(pin);
#endif #endif
servos[pin - 2].attach(pin); servos[pin - SERVO_OFFSET].attach(pin);
} }
} }


Expand All @@ -217,7 +217,7 @@ void Dino::servoWrite() {
#ifdef debug #ifdef debug
Serial.print("Servo write "); Serial.print(val); Serial.print(" to pin "); Serial.println(pin); Serial.print("Servo write "); Serial.print(val); Serial.print(" to pin "); Serial.println(pin);
#endif #endif
servos[pin - 2].write(val); servos[pin - SERVO_OFFSET].write(val);
} }


// CMD = 90 // CMD = 90
Expand Down
2 changes: 2 additions & 0 deletions src/lib/Dino.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
// Allocate listener storage based on what board we're running. // Allocate listener storage based on what board we're running.
#if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) #if defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__)
# define PIN_COUNT 70 # define PIN_COUNT 70
# define SERVO_OFFSET 22
#else #else
# define PIN_COUNT 22 # define PIN_COUNT 22
# define SERVO_OFFSET 2
#endif #endif


// Uncomment this line to enable debugging mode. // Uncomment this line to enable debugging mode.
Expand Down

0 comments on commit d30e070

Please sign in to comment.