Created
December 15, 2011 15:58
-
-
Save codejoust/1481607 to your computer and use it in GitHub Desktop.
arduino_wii
This file contains hidden or 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 drive1; | |
Servo drive2; | |
void setup(){ | |
Serial.begin(9600); | |
drive1.attach(5); | |
drive2.attach(6); | |
} | |
int get_serial_num(){ | |
int out = 0, i = 0, in; | |
while(true){ | |
in = Serial.read(); | |
if (in > 0 && in > 47 && in < 58){ | |
out += ((in - 48) * (pow(10, Serial.available()))); | |
} else { break; } | |
i++; | |
} | |
return out; | |
} | |
void loop(){ | |
int in, in2; | |
while(true){ | |
if (Serial.available()){ | |
if (Serial.read() == 'b'){ | |
in = get_serial_num(); | |
Serial.print(in, DEC); | |
Serial.println(); | |
drive1.write(in); | |
drive2.write (in); | |
} | |
Serial.flush(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment