So I decided to resurrect a project I was working on as a kid. Its a 4 motor remote controlled car, controlled by the Adafruit MotorShield V2, and an Infra-red receiver with the numbers and letters, VS, 1838B.
Now I'm nearly finished with the project, the motors can run perfectly, I've recorded the codes that the remote sends, and the receiver receives the code and acts. There is one problem though, that I encountered last time. With my code the receiver accepts the code for instance "0xFF629D," which tells the motors to run forward, but it is unable to accept the next code as the arduino is focused on running the motors, and not accepting the next code from the remote.
I'm quite sure the solution is very simple, but I'm only 15, and up and coming engineer.
Of course here's my code:
#include "IRLibAll.h"
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
Adafruit_DCMotor *myMotor2 = AFMS.getMotor(2);
Adafruit_DCMotor *myMotor3 = AFMS.getMotor(3);
Adafruit_DCMotor *myMotor4 = AFMS.getMotor(4);
int ledPin = 10;
IRrecvPCI myReceiver(2);
IRdecode myDecoder;
void setup() {
pinMode(ledPin, OUTPUT);
AFMS.begin();
Serial.begin(9600);
delay(2000); while (!Serial);
myReceiver.enableIRIn();
Serial.println(F("Ready to receive IR signals"));
myMotor->setSpeed(150);
myMotor2->setSpeed(150);
myMotor3->setSpeed(150);
myMotor4->setSpeed(150);
}
void loop() {
if (myReceiver.getResults()) {
myDecoder.decode();
if (myDecoder.protocolNum == NEC) {
switch (myDecoder.value) {
case 0xFFA857: //DOWN BUTTON
myMotor->run(BACKWARD);
myMotor2->run(BACKWARD);
myMotor3->run(BACKWARD);
myMotor4->run(BACKWARD);
myReceiver.enableIRIn();
break;
case 0xFF629D: //UP BUTTON
myMotor->run(FORWARD);
myMotor2->run(FORWARD);
myMotor3->run(FORWARD);
myMotor4->run(FORWARD);
myReceiver.enableIRIn();
break;
case 0xFF02FD: //OK BUTTON
myMotor->run(RELEASE);
myMotor2->run(RELEASE);
myMotor3->run(RELEASE);
myMotor4->run(RELEASE);
myReceiver.enableIRIn();
break;
case 0xFF220D: //LEFT BUTTON
myReceiver.enableIRIn();
break;
case 0xFFC23D: //RIGHT BUTTON
myReceiver.enableIRIn();
break;
}
myReceiver.enableIRIn();
}
}
}
Sorry for all the words, but thanks in advance.
sketch_aug25a.ino (1.77 KB)