HI All.
I'm using the Aduino UNO r3
I have a sketch that has 4 x void() sections.
I want to keep the board asleep for as long as possible to save battery life.
When the board senses an interrupt it has to wake up read and report the values of an ADXL345 accelerometer then go back to sleep.
My question is where do I put the code in the sketch?
On the included code sketch, from the yellow highlighted line that says void loop, onwards is what I have actually working. The board goes to sleep and wakes up with the GREEN highlighted bit being the first thing I see. My sense of logic is saying that the ADXL code should go in just after this line.
The code I think I want to use will be on the lines of; read ADXL X Axis, read ADXL Y Axis, if X Axis is greater than Y Axis turn on the red LED else turn on the green LED. if there is no interrupt (trigger to wake up the board) let the board go back to sleep.
I hope this is clear.
Thanks for looking.
The code is;
// Code to understand Loop()s
// I have a sketch that has the following construction/layout;
#include all the libraries needed
#define variables etc
void setup () {
Serial.begin(9600) ;
pinMode
pinMode etc
}
void loop() {
// Put board to sleep
void Going_To_Sleep() {
sleep_enable();
//Enabling sleep mode
attachInterrupt(0, wakeUp, LOW); //attaching a interrupt to pin d2
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
// Enter full sleep mode
digitalWrite(LED_BUILTIN,LOW); //turning
LED off
delay(1000); //wait a second to allow the led to turn off before sleeping
sleep_cpu(); //activating sleep mode
(GREEN HIGHLIGHTED BIT) Serial.println("just woke up!") ; //next line of code executed after interrupt
digitalWrite(LED_BUILTIN,HIGH);//turning LED on
}
void wakeUp() {
Serial.println("Interrrupt Fired"); //Print message to serial monitor
sleep_disable();//Disable sleep mode
detachInterrupt(0); //Removes the interrupt from pin 2;
}