Skip to content

Instantly share code, notes, and snippets.

@mplacona
Created November 6, 2019 09:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mplacona/0cce9f5d7e7687dc3a49832f1d62169c to your computer and use it in GitHub Desktop.
Save mplacona/0cce9f5d7e7687dc3a49832f1d62169c to your computer and use it in GitHub Desktop.
#include <avr/sleep.h>
#include <avr/interrupt.h>
#include <Heart.h>
/*
Android Beating Heart V2- Sketch
Marcos Placona 2019
*/
const int switchPin = 3;
const int statusLED = 4;
Heart heart(statusLED, 1.0);
void setup() {
pinMode(switchPin, INPUT);
digitalWrite(switchPin, HIGH);
pinMode(statusLED, OUTPUT);
// Flash quick sequence so we know setup has started
for (int k = 0; k < 10; k = k + 1) {
if (k % 2 == 0) {
digitalWrite(statusLED, HIGH);
}
else {
digitalWrite(statusLED, LOW);
}
delay(250);
} // for
} // setup
void sleep() {
GIMSK |= _BV(PCIE); // Enable Pin Change Interrupts
PCMSK |= _BV(PCINT3); // Use PB3 as interrupt pin
ADCSRA &= ~_BV(ADEN); // ADC off
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // replaces above statement
sleep_enable(); // Sets the Sleep Enable bit in the MCUCR Register (SE BIT)
sei(); // Enable interrupts
sleep_cpu(); // sleep
cli(); // Disable interrupts
PCMSK &= ~_BV(PCINT3); // Turn off PB3 as interrupt pin
sleep_disable(); // Clear SE bit
ADCSRA |= _BV(ADEN); // ADC on
sei(); // Enable interrupts
} // sleep
ISR(PCINT0_vect) {
// This is called when the interrupt occurs, but I don't need to do anything in it
}
void loop() {
sleep();
heart.beatForPeriod(10);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment