hello,
please help mi , i m confuse how to write source code .
when we press switch 7 then pwm generate and then press sw 2 for 4 min delay then loop start and execute delay that time no other instruction or function operate. becoz mcu busy in delay. we need to operate other switch case whenever key press but delay remains continuous running, only PWM changes that time .we use timer 1 for PWM generation... how to fix it please help mi .... give mi suggestion for it .
int PWM = 9;
int status[] = {0,0,0,0};
static const uint32_t DELAY_1_S = 1000UL;
static const uint32_t DELAY_1_MINUTE = DELAY_1_S * 60UL;
static const uint32_t DELAY_1_HOUR = DELAY_1_MINUTE * 60UL;
void setup()
{
Serial.begin(9600);
pinMode(PWM, OUTPUT);
}
void loop()
{
switch(results.value)
{ case sw5:
if(status[1] == 1)
{ ////Off the pwm
digitalWrite(PWM, LOW);
status[1] = 0;
}
else ////ON the pwm
{
digitalWrite(PWM, HIGH); // turn it on when the button is pressed
status[1] = 1; // and set its state as ON
TCCR1B = TCCR1B & ~ ((1 << CS12) | (1 << CS11) | (1 << CS10));
TCCR1A = (1 << COM1A1) | (0 << COM1A0)| (1 << COM1B1) | (1 <<
COM1B0) | (1 << WGM11) | (0 << WGM10);
TCCR1B = (0 << ICNC1) |(0 << ICES1)| (1 << WGM13) | (1 <<
WGM12)| (0 << CS12) | (0 << CS11) | (0 << CS10);
ICR1 = 48;
// OCR1A = 0;
TCCR1B = TCCR1B | (0 << CS12) | (1 << CS11) | (0 << CS10);
}
break;
case sw1:
if(status[1] == 1)
{
Serial.println("2 MIN TIMER ON%");
delay(2UL * DELAY_1_MINUTE); /// 2 MIN setting
digitalWrite(PWM, LOW);
}
break;
case sw2:
if(status[1] == 1)
{
delay(4UL * DELAY_1_MINUTE); /// FOR 4 MIN
digitalWrite(PWM, LOW);
}
break;
case sw3:
if(status[1] == 1)
{
delay(6UL * DELAY_1_MINUTE); /// FOR 6 MIN
digitalWrite(PWM, LOW);
}
break;
case sw4:
if(status[1] == 1)
{
delay(8UL * DELAY_1_MINUTE); /// FOR 8 MIN
digitalWrite(PWM, LOW);
}
break;
case sw6:
if(status[1] == 1)
{
OCR1A = 4;
}
break;
case sw7:
if(status[1] == 1)
{
OCR1A = 25;
}
break;
case sw8:
if(status[1] == 1)
{
OCR1A = 35;
}
break;
}
}