Right now I'm just testing that the arduino and IR receiver are outputting the correct info before testing it completely out with the motor controller and motors.
Currently, pressing up, down, and enter on the remote have the desired effect of increasing, decreasing, and resetting the speed of the motor. However, when I press left or right it has the same effect as enter in that s and i remain the same and the speeds of the left and right motor are 0.
I didn't bother including a circuit as I am receiving the IR code for the left and right buttons in the serial monitor, it just doesn't increment/decrement i. Any ideas as to why this would be the case?
Thanks.
I am open to any suggestions/corrections/etc.
#include <IRremote.h>
//Right motor
const int enablepinA = 3;
const int drivepin1 = 2;
const int drivepin2 = 4;
//Left motor
const int enablepinB = 5;
const int drivepin3 = 6;
const int drivepin4 = 7;
const int RECV_PIN = 8;
IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned long key_value = 0;
int speed[] = {240, 180, 120, 0, 120, 180, 240}; //PMW values up to 255
int s = 3; //index for speed vector
byte d = 00000101; // index of high and low for driver pins
int turn[] = {240, 180, 0, 180, 240}; // PMW values up to 255
int i = 2; //index for turning direction
int right = 0;
int left = 0;
void setup() {
Serial.begin(9600);
irrecv.enableIRIn();
irrecv.blink13(true);
/* pinMode(enablepinA, OUTPUT);
pinMode(drivepin1, OUTPUT);
pinMode(drivepin2, OUTPUT);
pinMode(enablepinB, OUTPUT);
pinMode(drivepin3, OUTPUT);
pinMode(drivepin4, OUTPUT);*/
}
void loop() {
//direction 1
if (irrecv.decode(&results)){
if (results.value == 0xFFFFFFFF)
results.value = key_value;
switch(results.value) {
case 0x9EB92:
Serial.println("up");
s++;
i=2;
break;
case 0x5EB92:
Serial.println("down");
s--;
i=2;
break;
case 0x3EB92:
Serial.println("right");
s=3;
i = i + 1;
break;
case 0xDEB92:
Serial.println("left");
s=3;
i = i - 1;
break;
case 0xD0B92:
Serial.println("enter");
left=0;
right=0;
s=3;
i=2;
break;
}
key_value = results.value;
irrecv.resume();
}
if (s>6)
s=6;
if (s<0)
s=0;
if (i>4)
i=4;
if (i<0)
i=0;
if (i=2) {
if (s>=3) {
d = 00000101;
}
else {
d = 00001010;
}
left = speed[s];
right = speed[s];
}
if (i != 2) {
if (i>2) {
left = turn[i];
right = 120;
}
else {
right = turn[i];
left = 120;
}
}
Serial.print(results.value);
Serial.print(",");
Serial.print(left);
Serial.print(",");
Serial.print(right);
Serial.print(",");
Serial.print(s);
Serial.print(",");
Serial.print(i);
Serial.print(",");
Serial.println(d);
delay(1000);
/*digitalWrite(drivepin1, bitRead(d,0));
digitalWrite(drivepin2, bitRead(d,1));
analogWrite(enablepinA, right);
digitalWrite(drivepin3, bitRead(d,2));
digitalWrite(drivepin4, bitRead(d,3));
analogWrite(enablepinB, left); */
}