Created
June 12, 2016 22:35
-
-
Save remcoder/b33870fc7d7b486f90255cf1e96bf164 to your computer and use it in GitHub Desktop.
My son's 'roadblock with lights' toy broke. So decided to fix it and while at it I though to myself, why not spice it up a little bit by adding a micro to it?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/sleep.h> | |
// Utility macros | |
#define adc_disable() (ADCSRA &= ~(1<<ADEN)) // disable ADC (before power-off) | |
#define adc_enable() (ADCSRA |= (1<<ADEN)) // re-enable ADC | |
const int ledPin1 = 1; | |
const int ledPin2 = 2; | |
const int ledPin3 = 3; | |
const int ledPin4 = 4; | |
const int inputPin = 0; | |
void enterSleep(void) | |
{ | |
pinMode(ledPin1, INPUT); | |
pinMode(ledPin2, INPUT); | |
pinMode(ledPin3, INPUT); | |
pinMode(ledPin4, INPUT); | |
sleep_enable(); | |
sleep_cpu(); | |
} | |
void setup() { | |
pinMode(ledPin1, OUTPUT); | |
pinMode(ledPin2, OUTPUT); | |
pinMode(ledPin3, OUTPUT); | |
pinMode(ledPin4, OUTPUT); | |
pinMode(inputPin, INPUT_PULLUP); | |
adc_disable(); // ADC uses ~320uA | |
set_sleep_mode(SLEEP_MODE_PWR_DOWN); | |
} | |
void blink() { | |
digitalWrite(ledPin1, HIGH); | |
delay(200); | |
digitalWrite(ledPin1, LOW); | |
digitalWrite(ledPin2, HIGH); | |
delay(200); | |
digitalWrite(ledPin2, LOW); | |
digitalWrite(ledPin3, HIGH); | |
delay(200); | |
digitalWrite(ledPin3, LOW); | |
digitalWrite(ledPin4, HIGH); | |
delay(200); | |
digitalWrite(ledPin4, LOW); | |
delay(1000); | |
} | |
void loop() { | |
for(int i=0 ; i< 5 ; i++) { | |
blink(); | |
} | |
enterSleep(); | |
// Continue after reset | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment