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
Expand Up @@ -3,7 +3,9 @@
## 0.11.2

* 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.

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

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')
end
end
Expand Down
8 changes: 4 additions & 4 deletions src/lib/Dino.cpp
Expand Up @@ -113,13 +113,13 @@ long Dino::timeSince(long event) {
// CMD = 00 // Pin Mode
void Dino::setMode() {
if (val == 0) {
removeListener();
pinMode(pin, OUTPUT);
#ifdef debug
Serial.print("Set pin "); Serial.print(pin); Serial.print(" to "); Serial.println("OUTPUT mode");
#endif
}
else {
removeListener();
pinMode(pin, INPUT);
#ifdef debug
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
Serial.print("Detaching servo"); Serial.print(" on pin "); Serial.println(pin);
#endif
servos[pin - 2].detach();
servos[pin - SERVO_OFFSET].detach();
}
else {
#ifdef debug
Serial.print("Attaching servo"); Serial.print(" on pin "); Serial.println(pin);
#endif
servos[pin - 2].attach(pin);
servos[pin - SERVO_OFFSET].attach(pin);
}
}

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

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

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

0 comments on commit d30e070

Please sign in to comment.