Created
October 30, 2011 01:52
-
-
Save casidiablo/1325361 to your computer and use it in GitHub Desktop.
Código en Arduino para mover el brazo de John Nicolls
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
#include <Servo.h> | |
Servo servo1; | |
Servo servo2; | |
int pos = 90; // variable to store the servo position | |
int NONE = -1; | |
int ANTEBRAZO = 1; | |
int BRAZO = 2; | |
int mode = NONE; | |
void setup() | |
{ | |
Serial.begin(9600); | |
servo1.attach(11); | |
servo2.attach(12); | |
} | |
void loop() | |
{ | |
if ( Serial.available()) { | |
char ch = Serial.read(); | |
switch(ch) { | |
case 'a': | |
mode = ANTEBRAZO; | |
pos = 0; | |
break; | |
case 'b': | |
mode = BRAZO; | |
pos = 0; | |
break; | |
case ';': | |
if(mode != NONE){ | |
Serial.print("Moving to "); | |
Serial.print(pos); | |
Serial.println(" degrees"); | |
if(pos < 0){ | |
pos = 0; | |
} | |
if(pos > 179){ | |
pos = 179; | |
} | |
if(mode == ANTEBRAZO){ | |
servo1.write(pos); | |
} else if(mode == BRAZO){ | |
servo2.write(pos); | |
} | |
mode = NONE; | |
} | |
break; | |
case '0'...'9': | |
if(mode != NONE){ | |
int part = ch - '0'; | |
if(pos > 0){ | |
pos *= 10; | |
} | |
pos += part; | |
} | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment