1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-07-30 16:24:09 +03:00

Fixed robot libraries and examples for unified Arduino core

This commit is contained in:
Xun Yang
2013-08-21 23:04:42 +02:00
parent 293e46bfb4
commit ec31a2ee5c
34 changed files with 2984 additions and 243 deletions

View File

@ -1,35 +1,15 @@
/* 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!
you can control it like a RC car.
Using the remote control comes with sensor
pack, You can make the robot move around
without even touching it!
Circuit:
* Arduino Robot
* Connect the IRreceiver to TDK2
* Sony compatible remote control
* Connect the IRreceiver to D2
* Remote control from Robot sensor pack
based on the IRremote library
by Ken Shirriff
@ -45,79 +25,67 @@
// include the necessary libraries
#include <IRremote.h>
#include <IRremoteTools.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
#define IR_CODE_FORWARD 284154405
#define IR_CODE_BACKWARDS 284113605
#define IR_CODE_TURN_LEFT 284129925
#define IR_CODE_TURN_RIGHT 284127885
#define IR_CODE_CONTINUE -1
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
boolean isActing=false; //If the robot is executing command from remote
long timer;
const long TIME_OUT=150;
void setup() {
// initialize the Robot, SD card, display, and speaker
Serial.begin(9600);
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
beginIRremote(); // Start the receiver
}
void loop() {
// if there is an IR command, process it
if (irrecv.decode(&results)) {
if (IRrecived()) {
processResult();
irrecv.resume(); // resume receiver
resumeIRremote(); // resume receiver
}
//If the robot does not receive any command, stop it
if(isActing && (millis()-timer>=TIME_OUT)){
Robot.motorsStop();
isActing=false;
}
}
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){
unsigned long res = getIRresult();
switch(res){
case IR_CODE_FORWARD:
Robot.stroke(0, 0, 0);
Robot.text("Forward", 5, 36);
Robot.motorsWrite(255, 255);
delay(300);
Robot.motorsStop();
changeAction(1,1); //Move the robot forward
break;
case IR_CODE_BACKWARDS:
Robot.stroke(0, 0, 0);
Robot.text("Backwards", 5, 36);
Robot.motorsWrite(-255, -255);
delay(300);
Robot.motorsStop();
changeAction(-1,-1); //Move the robot backwards
break;
case IR_CODE_TURN_LEFT:
Robot.stroke(0, 0, 0);
Robot.text("Left", 5, 36);
Robot.motorsWrite(-255, 255);
delay(100);
Robot.motorsStop();
changeAction(-0.5,0.5); //Turn the robot left
break;
case IR_CODE_TURN_RIGHT:
Robot.stroke(0, 0, 0);
Robot.text("Right", 5, 36);
Robot.motorsWrite(255, -255);
delay(100);
Robot.motorsStop();
changeAction(0.5,-0.5); //Turn the robot Right
break;
case IR_CODE_CONTINUE:
timer=millis(); //Continue the last action, reset timer
break;
}
}
void changeAction(float directionLeft, float directionRight){
Robot.motorsWrite(255*directionLeft, 255*directionRight);
timer=millis();
isActing=true;
}