[136] | 1 | /*
|
---|
| 2 | Esplora Pong
|
---|
| 3 |
|
---|
| 4 | This sketch connects serially to a Processing sketch to control a Pong game.
|
---|
| 5 | It sends the position of the slider and the states of three pushbuttons to the
|
---|
| 6 | Processing sketch serially, separated by commas. The Processing sketch uses that
|
---|
| 7 | data to control the graphics in the sketch.
|
---|
| 8 |
|
---|
| 9 | The slider sets a paddle's height
|
---|
| 10 | Switch 1 is resets the game
|
---|
| 11 | Switch 2 resets the ball to the center
|
---|
| 12 | Switch 3 reverses the players
|
---|
| 13 |
|
---|
| 14 | You can play this game with one or two Esploras.
|
---|
| 15 |
|
---|
| 16 | Created on 22 Dec 2012
|
---|
| 17 | by Tom Igoe
|
---|
| 18 |
|
---|
| 19 | This example is in the public domain.
|
---|
| 20 | */
|
---|
| 21 |
|
---|
| 22 | #include <Esplora.h>
|
---|
| 23 |
|
---|
| 24 | void setup() {
|
---|
| 25 | Serial.begin(9600); // initialize serial communication
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | void loop() {
|
---|
| 29 | // read the slider and three of the buttons
|
---|
| 30 | int slider = Esplora.readSlider();
|
---|
| 31 | int resetButton = Esplora.readButton(SWITCH_1);
|
---|
| 32 | int serveButton = Esplora.readButton(SWITCH_3);
|
---|
| 33 | int switchPlayerButton = Esplora.readButton(SWITCH_4);
|
---|
| 34 |
|
---|
| 35 | Serial.print(slider); // print the slider value
|
---|
| 36 | Serial.print(","); // add a comma
|
---|
| 37 | Serial.print(resetButton); // print the reset button value
|
---|
| 38 | Serial.print(","); // add another comma
|
---|
| 39 | Serial.print(serveButton); // print the serve button value
|
---|
| 40 | Serial.print(","); // add another comma
|
---|
| 41 | Serial.println(switchPlayerButton); // print the last button with a newline
|
---|
| 42 | delay(10); // delay before sending the next set
|
---|
| 43 | }
|
---|
| 44 |
|
---|