Step 19Program
////////////////////////// ARDUINO /////////////////////
//tests all servos and sound
#include <Servo.h>
Servo armRight; // create servo object to control a servo
int pos = 0; // variable to store the servo position
Servo armLeft;
Servo head;
Servo wheelRight;
Servo wheelLeft;
int soundPin = 3;
int pitch;
void setup()
{
armRight.attach(11);
head.attach(10);
armLeft.attach(9);
wheelRight.attach(6);
wheelLeft.attach(5);
}
void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
armLeft.write(pos);
armRight.write(pos); // tell servo to go to position in variable 'pos'
head.write(pos);
wheelRight.write(pos);
wheelLeft.write(pos);
pitch = map(pos, 0 ,180, 31,4978); //map position to tone
tone(soundPin, pitch, 200); // pin, note, time?
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
armLeft.write(pos);
armRight.write(pos); // tell servo to go to position in variable 'pos'
head.write(pos);
wheelRight.write(pos);
wheelLeft.write(pos);
pitch = map(pos, 0 ,180, 31,1000);
tone(soundPin, pitch, 200); // pin, note, time?
delay(15);
} // waits 15ms for the servo to reach the position
}
| « Previous Step | Download PDFView All Steps | Next Step » |
![]() |
Add Comment
|






















































