Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
I made it possible to run the DrawBot by feeding it an array. Haven't tested since I don't have servos.
/*
* 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