Question.3
The code given below blinks the LED.
Sam wants the LED always to be OFF. What should be the value of variable x in the code so the LED will always stay OFF?
Code
#include <avr/sleep.h>
#include <avr/interrupt.h>
#define LED 12
ISR(TIMER2_COMPA_vect) {
}
void timer2_config(){
// Configure Timer2 for CTC mode
TCCR2A = (1 << WGM21); // CTC mode
TCCR2B = (1 << CS22) | (1 << CS21) | (1 << CS20); // Prescaler 1024
OCR2A = 255; // Compare value for wake-up interval
// The below line of code generates an Interrupt when the value of Timer2 matches the value of the OCR2A register
TIMSK2 = (1 << OCIE2A); // Enable Timer2 Compare Match A Interrupt
sei(); // Enable global interrupts
}
void setup() {
int x = 0;
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
timer2_config();
sleep_enable();
if(x == 1){
set_sleep_mode(SLEEP_MODE_IDLE);
sleep_mode();
}
else if(x == 2){
set_sleep_mode(SLEEP_MODE_PWR_SAVE);
sleep_mode();
}
else if(x == 3){
set_sleep_mode(SLEEP_MODE_STANDBY);
sleep_mode();
}
else if(x == 4){
set_sleep_mode(SLEEP_MODE_EXT_STANDBY);
sleep_mode();
}
sleep_disable();
}
void loop() {
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW);
delay(500);
}