#include #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 buttonPin = 1; //setting button pin const int ledPin = 0; // setting LED pin int buttonPushCounter1 = 1; // counts the button pushes int buttonState1 = 1; // tracks the button state int lastButtonState1 = 0; // last state of the button int buttonState = 0; // Button status int lastButtonState = LOW; //Button set to LOW long lastDebounceTime = 0; // Debounce status long debounceDelay = 50; // Debounce timer void setup() { pinMode(ledPin, OUTPUT); // Sets LED as output pinMode(buttonPin, INPUT); // Sets button as input 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); } //Sleep mode int modefour() { analogWrite(ledPin,8); delay(20); analogWrite(ledPin,0); delay(20); analogWrite(ledPin,8); delay(20); analogWrite(ledPin,0); delay(20); analogWrite(ledPin,8); delay(20); analogWrite(ledPin,0); buttonPushCounter1 = 1; system_sleep(); } void loop() { // All the debound button press stuff int reading = digitalRead(buttonPin); buttonState1 = digitalRead(buttonPin); if (reading != lastButtonState) { lastDebounceTime = millis(); } if ((millis() - lastDebounceTime) > debounceDelay) { if (reading != buttonState) { buttonState = reading; if (buttonState1 != lastButtonState1) { if (buttonState1 == HIGH) { buttonPushCounter1++; if (buttonPushCounter1 == 5) { buttonPushCounter1 = 1;} } else { } } lastButtonState1 = buttonState1; } } lastButtonState = reading; //switching modes: if (buttonPushCounter1 == 1) { modeone(); } if (buttonPushCounter1 == 2) { modetwo(); } if (buttonPushCounter1 == 3) { modethree(); } if (buttonPushCounter1 == 4) { modefour(); } } //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) { }