mirror of
https://github.com/esp8266/Arduino.git
synced 2025-08-07 00:04:36 +03:00
Run new astyle formatter against all the examples
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
/* 08 Remote Control
|
||||
|
||||
If you connect a IR receiver to the robot,
|
||||
you can control it like a RC car.
|
||||
Using the remote control comes with sensor
|
||||
pack, You can make the robot move around
|
||||
|
||||
If you connect a IR receiver to the robot,
|
||||
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:
|
||||
Circuit:
|
||||
* Arduino Robot
|
||||
* Connect the IRreceiver to D2
|
||||
* Remote control from Robot sensor pack
|
||||
@@ -14,12 +14,12 @@
|
||||
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
|
||||
*/
|
||||
|
||||
@@ -35,12 +35,12 @@
|
||||
#define IR_CODE_TURN_RIGHT 284127885
|
||||
#define IR_CODE_CONTINUE -1
|
||||
|
||||
boolean isActing=false; //If the robot is executing command from remote
|
||||
long timer;
|
||||
const long TIME_OUT=150;
|
||||
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
|
||||
// initialize the Robot, SD card, display, and speaker
|
||||
Serial.begin(9600);
|
||||
Robot.begin();
|
||||
Robot.beginTFT();
|
||||
@@ -56,36 +56,36 @@ void loop() {
|
||||
processResult();
|
||||
resumeIRremote(); // resume receiver
|
||||
}
|
||||
|
||||
|
||||
//If the robot does not receive any command, stop it
|
||||
if(isActing && (millis()-timer>=TIME_OUT)){
|
||||
if (isActing && (millis() - timer >= TIME_OUT)) {
|
||||
Robot.motorsStop();
|
||||
isActing=false;
|
||||
isActing = false;
|
||||
}
|
||||
}
|
||||
void processResult() {
|
||||
unsigned long res = getIRresult();
|
||||
switch(res){
|
||||
switch (res) {
|
||||
case IR_CODE_FORWARD:
|
||||
changeAction(1,1); //Move the robot forward
|
||||
changeAction(1, 1); //Move the robot forward
|
||||
break;
|
||||
case IR_CODE_BACKWARDS:
|
||||
changeAction(-1,-1); //Move the robot backwards
|
||||
changeAction(-1, -1); //Move the robot backwards
|
||||
break;
|
||||
case IR_CODE_TURN_LEFT:
|
||||
changeAction(-0.5,0.5); //Turn the robot left
|
||||
changeAction(-0.5, 0.5); //Turn the robot left
|
||||
break;
|
||||
case IR_CODE_TURN_RIGHT:
|
||||
changeAction(0.5,-0.5); //Turn the robot Right
|
||||
changeAction(0.5, -0.5); //Turn the robot Right
|
||||
break;
|
||||
case IR_CODE_CONTINUE:
|
||||
timer=millis(); //Continue the last action, reset timer
|
||||
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;
|
||||
void changeAction(float directionLeft, float directionRight) {
|
||||
Robot.motorsWrite(255 * directionLeft, 255 * directionRight);
|
||||
timer = millis();
|
||||
isActing = true;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user