Created
January 13, 2011 21:15
-
-
Save mathias/778622 to your computer and use it in GitHub Desktop.
I made it possible to run the DrawBot by feeding it an array. Haven't tested since I don't have servos.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Drawbot.pde | |
*/ | |
#include <Servo.h> | |
Servo leftServo; | |
Servo rightServo; | |
int servoPinL = 9; | |
int servoPinR = 10; | |
int a, i; | |
int servo_delay = 15; // 15 millisecond servo_delay between servo steps. | |
int servo_speed = 180; // Actually the angle the servo should go to, but we're using continuous | |
int length = 8; // How long the instructions array is + 1 for null char. Needs to be updated when instructions array changes. | |
// Instructions: r = right, l = left, f = forward, b = backwards. | |
char instructions[] = "rrllfbfb"; | |
void setup() { | |
leftServo.attach(servoPinL); | |
rightServo.attach(servoPinR); | |
} | |
void loop() { | |
for (i = 0; i < length; i += 1) { | |
switch(instructions[i]) { | |
case 'r': | |
right(); | |
break; | |
case 'l': | |
left(); | |
break; | |
case 'b': | |
back(); | |
break; | |
default: | |
case 'f': | |
forward(); | |
break; | |
} | |
delay(servo_delay); | |
} | |
} | |
void right() { | |
for(a = 0; a < servo_speed; a += 1) { | |
leftServo.write(-a); | |
rightServo.write(a); | |
delay(servo_delay); | |
} | |
leftServo.write(0); | |
rightServo.write(0); | |
delay(servo_delay); | |
} | |
void left() { | |
for(a = 0; a < servo_speed; a++) { | |
leftServo.write(a); | |
rightServo.write(-a); | |
delay(servo_delay); | |
} | |
leftServo.write(0); | |
rightServo.write(0); | |
delay(servo_delay); | |
} | |
void forward() { | |
for(a = 0; a < servo_speed; a++) { | |
leftServo.write(a); | |
rightServo.write(a); | |
delay(servo_delay); | |
} | |
leftServo.write(0); | |
rightServo.write(0); | |
delay(servo_delay); | |
} | |
void back() { | |
for(a = 0; a < servo_speed; a++) { | |
leftServo.write(-a); | |
rightServo.write(-a); | |
delay(servo_delay); | |
} | |
leftServo.write(0); | |
rightServo.write(0); | |
delay(servo_delay); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment