I am receiving a signal from ir receiver based on the receiver value, I am using a function in void loop(). In this function I am again receiving ir value and using switch statement to direct it to a case. Within that case I am using while statement (I am again receiving ir values) to run this function for two minutes. But the statements within the while statements are not running. Please help what I am doing wrong. My program is as follows.
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include “utility/Adafruit_PWMServoDriver.h”
#include <IRremote.h>
// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);
// Select which ‘port’ M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *myMotor1 = AFMS.getMotor(1);
Adafruit_DCMotor *myMotor2 = AFMS.getMotor(2);
Adafruit_DCMotor *myMotor3 = AFMS.getMotor(3);
Adafruit_DCMotor *myMotor4 = AFMS.getMotor(4);
// You can also make another motor on port M2
//Adafruit_DCMotor *myOtherMotor = AFMS.getMotor(2);
int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
AFMS.begin(); // create with the default frequency 1.6KHz
//AFMS.begin(1000); // OR with a different frequency, say 1KHz
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
}
}
void loop()
{
if (irrecv.decode(&results)) // have we received an IR signal?
{
Serial.println(results.value, HEX);
translateIR2();
irrecv.resume();
}
}
void translateIR2() {
if (irrecv.decode(&results))
switch(results.value)
{
case 0x21:
unsigned long sec;
unsigned long A;
A=millis();
while(sec < 120000){
// Statements…;
sec=millis()-A;
Serial.println(sec,HEX);
break;
default:
Serial.println(" other button ");
}
}
}