Try this. Not sure where your source came from - appears to have some Arduino-based I/O functions? Are you doing this in Atmel Studio with the compiler or in Arduino?
#include <avr/sleep.h>
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
//**here you set brightness of modes
int mode1 = 255;
int mode2 = 8;
const int ledPin = 0; // setting LED pin
unsigned int key __attribute__ ((section (".noinit")));
unsigned int mode __attribute__ ((section (".noinit")));
void setup() {
if(key==12345){ //check if RAM is still valid from last time
mode++; //yes, advance to next mode
if(mode>2) {mode=0;}
}
else{ //long power loss. default to first mode
mode=0; //default mode after long power off
key=12345; //initialize key for next power loss
}
pinMode(ledPin, OUTPUT); // Sets LED as output
sbi(GIMSK,PCIE); // Turn on Pin Change interrupt
sbi(PCMSK,PCINT1); // Which pins are affected by the interrupt
}
//mode one: LED is set to 100% brightness by default
int modeone() {
analogWrite(ledPin,mode1);
}
//mode two: LED is set to your preference of brightness (my default is about 30% = 76)
int modetwo() {
analogWrite(ledPin,mode2);
}
//mode three: strobe light, I set it to be the most disorienting in darkness but feel free to change on and off times (in [ms])
int modethree() {
digitalWrite(ledPin,HIGH);
delay(15);
digitalWrite(ledPin,LOW);
delay(100);
}
void loop() {
switch(mode){
default:
case 0:
modeone();
break;
case 1:
modetwo();
break;
case 2:
modethree();
break;
}
}
//loop end
void system_sleep() {
cbi(ADCSRA,ADEN); // Switch Analog to Digital converter OFF
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Set sleep mode
sleep_mode(); // System sleeps here
sbi(ADCSRA,ADEN); // Switch Analog to Digital converter ON
}
ISR(PCINT0_vect) {
}