Delete comment from: Ken Shirriff's blog
Hi! I have a code for a DC motor control as well as a problem with the code:
/*
* http://arcfn.com
*/
#include
int leftPins[] = {5,7,4}; //Pin 5 enables L293D, pins 7 and 4 are intended for PWM, i.e. motor direction
int RECV_PIN = 2;//This is the INT0 Pin of the ATMega8
IRrecv irrecv(RECV_PIN);
decode_results results;
int wait = 5000;
void setup() {
//Serial.begin(9600);
for (int i = 0; i < 3; i++) pinMode(leftPins[i], OUTPUT);// pinMode(leftPins[0], INPUT);
pinMode(leftPins[0], OUTPUT);
irrecv.enableIRIn();//Start the receiver
}//setup
void loop() {
if (irrecv.decode(&results)) {
//Serial.println(results.value, HEX);
//Serial.println(results.value, DEC);
switch (results.value) {
//Now pay attention to analogWrite(leftPins[0], 0); on 3th and 4th rows.
//If nothing stopped the DC motor it would rotate endlessly
//and I would not be able to switch to another case.
//Stated simply, the code gets blocked.
//Asked simply, why? The method irrecv.resume(); supports interrupt, doesn't it?
case 0x1FE609F: digitalWrite(leftPins[1], LOW); digitalWrite(leftPins[2], HIGH); break;//Vol- on my remote
case 0x1FEA05F: digitalWrite(leftPins[1], HIGH); digitalWrite(leftPins[2], LOW); break;//Vol+ on my remote
case 0x1FE708F: analogWrite(leftPins[0], 122); delay(wait); analogWrite(leftPins[0], 0); break;//Button 6 on my remote
case 0x1FE9867: analogWrite(leftPins[0], 255); delay(wait); analogWrite(leftPins[0], 0); break;//Button 9 on my remote
default: break;
}//switch
irrecv.resume(); //Receive the next value
}//if irrecv.decode
}//loop
The code blocks as it is explained in the comment just below the "switch". What does go wrong? Should I didn't stop the motor by typing code, I would not be able to switch between different cases by means of the remote control.
Any suggestions would be appreciated.
10x in advance!
Jul 6, 2012, 2:40:39 AM
Posted to A Multi-Protocol Infrared Remote Library for the Arduino

