Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Spark-Powered Angry Bird Swimmer
// D0 = Angle Down
// D1 = Angle Up
// D2 = Left
// D3 = Right
int pinLeft = D2;
int pinRight = D3;
int pinDown = D0;
int pinUp = D1;
int default_delay = 500;
void setup() {
// initWifi(); // channel 13 fix
pinMode(pinLeft, OUTPUT);
pinMode(pinRight, OUTPUT);
pinMode(pinUp, OUTPUT);
pinMode(pinDown, OUTPUT);
digitalWrite(pinLeft, LOW);
digitalWrite(pinRight, LOW);
digitalWrite(pinUp, LOW);
digitalWrite(pinDown, LOW);
Spark.function("birdCtrl", birdControl);
}
void loop() {
// Do nothing
}
/* void initWifi() {
unsigned long aiIntervalList[16];
for (int i=0; i<16; i++) { aiIntervalList[i] = 2000; }
wlan_ioctl_set_scan_params( 1000, 100, 100, 5, 0x1fff, -80, 0, 205, aiIntervalList );
wlan_start(0);
} */
int birdControl(String command) {
command.trim();
command.toUpperCase();
if(command.equals("LEFT"))
birdMove(pinLeft, default_delay);
else if(command.equals("RIGHT"))
birdMove(pinRight, default_delay);
else if(command.equals("UP"))
birdMove(pinUp, default_delay);
else if(command.equals("DOWN"))
birdMove(pinDown, default_delay);
else if(command.equals("FORWARD")) {
for(int i=0; i<2; i++) {
birdMove(pinLeft, default_delay);
delay(100);
birdMove(pinRight, default_delay);
delay(100);
}
} else if(command.equals("LLEFT"))
for(int i=0; i<2; i++)
birdMove(pinLeft, default_delay);
else if(command.equals("RRIGHT"))
for(int i=0; i<2; i++)
birdMove(pinRight, default_delay);
else
return 0;
return 1;
}
void birdMove(int p, int d) {
digitalWrite(D0, LOW);
digitalWrite(D1, LOW);
digitalWrite(D2, LOW);
digitalWrite(D3, LOW);
digitalWrite(p, HIGH);
delay(d);
digitalWrite(p, LOW);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.