Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- author : Patrick Dubois
- licence : none
- needs : IRremote Arduino Library Version 3.3.0 (at least)
- needs : Adafruit Motor Shield library Version 1.0.1 (for Adafruit Motor shield V1)
- */
- /*
- Specify which protocol(s) should be used for decoding.
- If no protocol is defined, all protocols are active.
- */
- //#define DECODE_DENON // Includes Sharp
- //#define DECODE_JVC
- //#define DECODE_KASEIKYO
- //#define DECODE_PANASONIC // the same as DECODE_KASEIKYO
- //#define DECODE_LG
- #define DECODE_NEC // Includes Apple and Onkyo
- //#define DECODE_SAMSUNG
- //#define DECODE_SONY
- //#define DECODE_RC5
- //#define DECODE_RC6
- //#define DECODE_BOSEWAVE
- //#define DECODE_LEGO_PF
- //#define DECODE_MAGIQUEST
- //#define DECODE_WHYNTER
- #define DECODE_DISTANCE // universal decoder for pulse width or pulse distance protocols
- #define DECODE_HASH // special decoder for all protocols
- #include <AFMotor.h>
- #define IR_USE_AVR_TIMER1 // by default used timer is TIMER2, also used by Adafruit_Motor-Shield-v1 - tx = pin 9
- #define IR_RECEIVE_PIN 2 // To be compatible with interrupt example, pin 2 is chosen here.
- #include <IRremote.h>
- AF_DCMotor R_motor(1); // defines Right motor connector
- AF_DCMotor L_motor(2); // defines Left motor connector
- IRrecv irrecv(IR_RECEIVE_PIN); // create instance of 'irrecv'
- int iSpeed = 64; // 48 - 240
- int irSpeed; // relative speed when turning
- bool bAvant;
- void setup() {
- Serial.begin(115200); // sets up Serial library at 115200 bps
- IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
- }
- void loop() {
- int nValue = 0;
- if (IrReceiver.decode()) { // have we received an IR signal
- // IrReceiver.printIRResultShort(&Serial);
- // IrReceiver.printIRResultRawFormatted(&Serial, true);
- // IrReceiver.printIRResultShort(&Serial);
- // Serial.println(IrReceiver.decodedIRData.protocol);
- // Serial.println(IrReceiver.decodedIRData.decodedRawData);
- // Serial.println(IrReceiver.decodedIRData.address);
- // Serial.println(IrReceiver.decodedIRData.command);
- nValue = IrReceiver.decodedIRData.command;
- Serial.println();
- Serial.println(nValue);
- switch (nValue) {
- case 69: // POWER
- case 71: { // FUNC/STOP
- //changes the following values to make the robot drive as straight as possible
- R_motor.run(RELEASE); // turns L motor off
- L_motor.run(RELEASE); // turns R motor off
- break;
- }
- case 67: { // FAST FORWARD - TURN RIGHT ON RUNNING
- if (bAvant) {
- L_motor.run(FORWARD);
- R_motor.setSpeed(irSpeed);
- R_motor.run(FORWARD);
- }
- else {
- R_motor.run(BACKWARD);
- L_motor.setSpeed(irSpeed);
- L_motor.run(BACKWARD);
- }
- break;
- }
- case 68: { // FAST BACK - TURN LEFT ON RUNNING
- if (bAvant) {
- R_motor.run(FORWARD);
- L_motor.setSpeed(irSpeed);
- L_motor.run(FORWARD);
- }
- else {
- L_motor.run(BACKWARD);
- R_motor.setSpeed(irSpeed);
- R_motor.run(BACKWARD);
- }
- break;
- }
- case 64: { // START / PAUSE
- break;
- }
- case 21: { // VOL- - SPEED DOWN
- iSpeed = iSpeed > 32 ? iSpeed - 16 : iSpeed;
- irSpeed = iSpeed / 4;
- L_motor.setSpeed(iSpeed); // sets L motor speed
- R_motor.setSpeed(iSpeed); // sets R motor speed
- break;
- }
- case 70: { // VOL+ - SPEED UP
- iSpeed = iSpeed < 240 ? iSpeed + 16 : iSpeed;
- irSpeed = iSpeed / 4;
- L_motor.setSpeed(iSpeed); // sets L motor speed
- R_motor.setSpeed(iSpeed); // sets R motor speed
- break;
- }
- case 7: { // DOWN
- bAvant = false;
- L_motor.setSpeed(iSpeed); // sets L motor speed
- R_motor.setSpeed(iSpeed); // sets R motor speed
- R_motor.run(BACKWARD);
- L_motor.run(BACKWARD);
- break;
- }
- case 9: { // UP
- bAvant = true;
- L_motor.setSpeed(iSpeed); // sets L motor speed
- R_motor.setSpeed(iSpeed); // sets R motor speed
- R_motor.run(FORWARD);
- L_motor.run(FORWARD);
- break;
- }
- case 25: { // EQ
- break;
- }
- case 13: { // ST/REPT
- break;
- }
- case 22: { // 0
- break;
- }
- case 12: { // 1
- break;
- }
- case 24: { // 2
- break;
- }
- case 94: { // 3
- break;
- }
- case 8: { // 4 - TURN LEFT ON PLACE
- R_motor.run(FORWARD);
- L_motor.run(BACKWARD);
- break;
- }
- case 28: { // 5
- break;
- }
- case 90: { // 6 - TURN RIGHT ON PLACE
- L_motor.run(FORWARD);
- R_motor.run(BACKWARD);
- break;
- }
- case 66: { // 7
- break;
- }
- case 82: { // 8
- break;
- }
- case 74: { // 9
- break;
- }
- } // end switch
- IrReceiver.resume(); // receive the next value
- } // end if
- delay(250);
- } // end loop
Add Comment
Please, Sign In to add comment