1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-11 22:24:13 +01:00
Arduino/libraries/Esplora/examples/Experts/EsploraPong/EsploraPong.ino

45 lines
1.4 KiB
Arduino
Raw Normal View History

2012-12-24 03:49:09 +01:00
/*
Esplora Pong
2012-12-24 03:49:09 +01:00
This sketch connects serially to a Processing sketch to control a Pong game.
It sends the position of the slider and the states of three pushbuttons to the
Processing sketch serially, separated by commas. The Processing sketch uses that
2012-12-24 03:49:09 +01:00
data to control the graphics in the sketch.
2012-12-24 03:49:09 +01:00
The slider sets a paddle's height
Switch 1 is resets the game
Switch 2 resets the ball to the center
Switch 3 reverses the players
2012-12-24 03:49:09 +01:00
You can play this game with one or two Esploras.
2012-12-24 03:49:09 +01:00
Created on 22 Dec 2012
by Tom Igoe
2012-12-24 03:49:09 +01:00
This example is in the public domain.
*/
#include <Esplora.h>
void setup() {
2012-12-24 04:10:07 +01:00
Serial.begin(9600); // initialize serial communication
}
void loop() {
2012-12-24 04:10:07 +01:00
// read the slider and three of the buttons
int slider = Esplora.readSlider();
2012-12-24 04:10:07 +01:00
int resetButton = Esplora.readButton(SWITCH_1);
int serveButton = Esplora.readButton(SWITCH_3);
int switchPlayerButton = Esplora.readButton(SWITCH_4);
2012-12-24 04:10:07 +01:00
Serial.print(slider); // print the slider value
Serial.print(","); // add a comma
Serial.print(resetButton); // print the reset button value
Serial.print(","); // add another comma
Serial.print(serveButton); // print the serve button value
Serial.print(","); // add another comma
Serial.println(switchPlayerButton); // print the last button with a newline
delay(10); // delay before sending the next set
}