What exactly are the symptoms? How does it behave differently on the Uno vs the Duemilanove?but it does not work in uno
And what version of the IDE are you using?
Moderators: adafruit_support_bill, adafruit
What exactly are the symptoms? How does it behave differently on the Uno vs the Duemilanove?but it does not work in uno
Code: Select all
#include <ServoTimer1.h>
ServoTimer1 servo1;
ServoTimer1 servo2;
// create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
void setup()
{
servo1.attach(9);
servo2.attach(10);
}
void loop()
{
for(pos = 0; pos < 180; pos += 1)
// goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
servo1.write(pos);
servo2.write (pos);
// tell servo to go to position in variable 'pos'
delay(39);
// waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
servo1.write(pos);
servo2.write (pos);
// tell servo to go to position in variable 'pos'
delay(30);
// waits 15ms for the servo to reach the position
}
}
Code: Select all
#include <AFMotor.h>
#include <ServoTimer1.h>
AF_DCMotor motor1(1, MOTOR12_64KHZ);
AF_DCMotor motor2(2, MOTOR12_64KHZ);
ServoTimer1 servo1;
ServoTimer1 servo2;
ServoTimer1 servo3;
const int IRpin = 1;
// analog pin for reading the IR sensor
const int voicePin=2;
const int eyePin=12;//always on
boolean servDir;
int servPos;
void setup()
{
Serial.begin(9600);
motor1.setSpeed(250);
motor2.setSpeed(250);
pinMode(voicePin, OUTPUT);
servo1.attach(9);// wall-e arm
servo2.attach(10);//wall-e arm
servo3.attach(3);//wall-e head
servPos=45;
servDir=true;
}
void loop()
{
digitalWrite(voicePin, HIGH);//wall-e talks
// sets the voice on
delay(1000);
// waits for 1 seconds
digitalWrite(voicePin, LOW);
// sets the voice off
delay(5000);
// waits for 5 seconds
float volts = analogRead(IRpin)*0.0048828125;
// value from sensor * (5/1024) - if running 3.3.volts then change 5 to 3.3
float distance = 65*pow(volts, -1.10);
// worked out from graph 65 = theretical distance /
Serial.println(distance); // print the distance
long duration, inches, cm;
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
servo1.attach(9);// wall-e arm
if (servDir == true) servPos = servPos + 7;
if (servDir == false) servPos = servPos - 7;
if (servPos < 45) servDir = true;
if (servPos > 125) servDir = false;
delay(100);
Serial.print(servPos);
Serial.print(servDir);
servo2.attach(10);// wall-e arm
if (servDir == true) servPos = servPos + 7;
if (servDir == false) servPos = servPos - 7;
if (servPos < 45) servDir = true;
if (servPos > 125) servDir = false;
delay(100);
Serial.print(servPos);
Serial.print(servDir);
servo3.attach(3);//wall-e head
if (servDir == true) servPos = servPos + 7;
if (servDir == false) servPos = servPos - 7;
if (servPos < 45) servDir = true;
if (servPos > 135) servDir = false;
delay(100);
Serial.print(servPos);
Serial.print(servDir);
{
Serial.print("Back ");
motor1.run(BACKWARD);
motor2.run(BACKWARD);
delay(500);
Serial.print("Turn ");
motor1.run(FORWARD);
motor2.run(BACKWARD);
delay(500);
}
{
Serial.print("Forward ");
motor1.run(FORWARD);
motor2.run(FORWARD);
}
Serial.println();
servo1.write(servPos);
delay(100);
servo2.write(servPos);
delay(100);
servo3.write(servPos);
delay(100);
}
long microsecondsToInches(long microseconds)
{
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;}
The following pins are in use only if the DC/Stepper noted is in use:
Digital pin 11: DC Motor #1 / Stepper #1 (activation/speed control)
Digital pin 3: DC Motor #2 / Stepper #1 (activation/speed control)
Digital pin 5: DC Motor #3 / Stepper #2 (activation/speed control)
Digital pin 6: DC Motor #4 / Stepper #2 (activation/speed control)
What pins are not used on the motor shield?
All 6 analog input pins are available. They can also be used as digital pins (pins #14 thru 19)
Digital pin 2, and 13 are not used.
The following pins are in use only if the DC/Stepper noted is in use:
Digital pin 11: DC Motor #1 / Stepper #1 (activation/speed control)
Digital pin 3: DC Motor #2 / Stepper #1 (activation/speed control)
Digital pin 5: DC Motor #3 / Stepper #2 (activation/speed control)
Digital pin 6: DC Motor #4 / Stepper #2 (activation/speed control)
The following pins are in use if any DC/steppers are used
Digital pin 4, 7, 8 and 12 are used to drive the DC/Stepper motors via the 74HC595 serial-to-parallel latch
The following pins are used only if that particular servo is in use:
Digitals pin 9: Servo #1 control
Digital pin 10: Servo #2 control