Skip to content

Instantly share code, notes, and snippets.

@codejoust
Created December 15, 2011 15:58
Show Gist options
  • Save codejoust/1481607 to your computer and use it in GitHub Desktop.
Save codejoust/1481607 to your computer and use it in GitHub Desktop.
arduino_wii
#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