aboutsummaryrefslogtreecommitdiff
path: root/libraries/Robot_Control/examples/explore/R08_Remote_Control
diff options
context:
space:
mode:
authorCristian Maglie <c.maglie@bug.st>2013-06-01 23:16:02 +0200
committerCristian Maglie <c.maglie@bug.st>2013-06-01 23:16:02 +0200
commit177ad96f866714a4962be57f69cd3d5a6334cde1 (patch)
tree1072239986340d6a239adac924eddf2e1d1ca566 /libraries/Robot_Control/examples/explore/R08_Remote_Control
parent6cff36ac5e85c74bcb45cc53491ad69d64520b36 (diff)
parentd90fcca5839d13d57ed527d4009b78d22dafbde7 (diff)
Merge branch 'merge-1.0.5' into ide-1.5.x-discovery
Diffstat (limited to 'libraries/Robot_Control/examples/explore/R08_Remote_Control')
-rw-r--r--libraries/Robot_Control/examples/explore/R08_Remote_Control/R08_Remote_Control.ino123
1 files changed, 123 insertions, 0 deletions
diff --git a/libraries/Robot_Control/examples/explore/R08_Remote_Control/R08_Remote_Control.ino b/libraries/Robot_Control/examples/explore/R08_Remote_Control/R08_Remote_Control.ino
new file mode 100644
index 0000000..fda21cb
--- /dev/null
+++ b/libraries/Robot_Control/examples/explore/R08_Remote_Control/R08_Remote_Control.ino
@@ -0,0 +1,123 @@
+/* 08 Remote Control
+
+ *******************
+ ***
+ ***This example code is in an experimental state.
+ ***You are welcome to try this with your robot,
+ ***and no harm will come to it. We will provide a
+ ***detailed description of an updated version of this
+ ***in a future update
+ ***
+ *** For this example to work you need:
+ ***
+ *** - download and install the IR-Remote library by Ken Shirriff
+ *** to be found at https://github.com/shirriff/Arduino-IRremote
+ *** - get a Sony remote control
+ ***
+ *** This example will be updated soon, come back to the Robot
+ *** page on the Arduino server for updates!!
+ ***
+ *******************
+
+ If you connect a IR receiver to the robot,
+ you can control it like you control a TV set.
+ Using a Sony compatiable remote control,
+ map some buttons to different actions.
+ You can make the robot move around without
+ even touching it!
+
+ Circuit:
+ * Arduino Robot
+ * Connect the IRreceiver to TDK2
+ * Sony compatible remote control
+
+ based on the IRremote library
+ by Ken Shirriff
+ http://arcfn.com
+
+ created 1 May 2013
+ by X. Yang
+ modified 12 May 2013
+ by D. Cuartielles
+
+ This example is in the public domain
+ */
+
+// include the necessary libraries
+#include <IRremote.h>
+#include <ArduinoRobot.h>
+
+// Define a few commands from your remote control
+#define IR_CODE_FORWARD 0x2C9B
+#define IR_CODE_BACKWARDS 0x6C9B
+#define IR_CODE_TURN_LEFT 0xD4B8F
+#define IR_CODE_TURN_RIGHT 0x34B8F
+
+int RECV_PIN = TKD2; // the pin the IR receiver is connected to
+IRrecv irrecv(RECV_PIN); // an instance of the IR receiver object
+decode_results results; // container for received IR codes
+
+void setup() {
+ // initialize the Robot, SD card, display, and speaker
+ Robot.begin();
+ Robot.beginTFT();
+ Robot.beginSD();
+
+ // print some text to the screen
+ Robot.stroke(0, 0, 0);
+ Robot.text("Remote Control code:", 5, 5);
+ Robot.text("Command:", 5, 26);
+ irrecv.enableIRIn(); // Start the receiver
+}
+
+void loop() {
+ // if there is an IR command, process it
+ if (irrecv.decode(&results)) {
+ processResult();
+ irrecv.resume(); // resume receiver
+ }
+}
+
+void processResult() {
+ unsigned long res = results.value;
+ // print the value to the screen
+ Robot.debugPrint(res, 5, 15);
+
+ if(res == IR_CODE_FORWARD || res == IR_CODE_BACKWARDS || res == IR_CODE_TURN_LEFT || res == IR_CODE_TURN_RIGHT) {
+ Robot.fill(255, 255, 255);
+ Robot.stroke(255, 255, 255);
+
+ Robot.rect(5, 36, 55, 10);
+ }
+ switch(results.value){
+ case IR_CODE_FORWARD:
+ Robot.stroke(0, 0, 0);
+ Robot.text("Forward", 5, 36);
+ Robot.motorsWrite(255, 255);
+ delay(300);
+ Robot.motorsStop();
+ break;
+ case IR_CODE_BACKWARDS:
+ Robot.stroke(0, 0, 0);
+ Robot.text("Backwards", 5, 36);
+ Robot.motorsWrite(-255, -255);
+ delay(300);
+ Robot.motorsStop();
+ break;
+ case IR_CODE_TURN_LEFT:
+ Robot.stroke(0, 0, 0);
+ Robot.text("Left", 5, 36);
+ Robot.motorsWrite(-255, 255);
+ delay(100);
+ Robot.motorsStop();
+ break;
+ case IR_CODE_TURN_RIGHT:
+ Robot.stroke(0, 0, 0);
+ Robot.text("Right", 5, 36);
+ Robot.motorsWrite(255, -255);
+ delay(100);
+ Robot.motorsStop();
+ break;
+ }
+}
+