Added some interrupt code to arduino
This commit is contained in:
parent
22dbc6e7ae
commit
ed3497fba4
3 changed files with 77 additions and 3 deletions
|
|
@ -4,12 +4,11 @@ the data to a central location.
|
|||
*/
|
||||
|
||||
|
||||
|
||||
void setup(){
|
||||
void setup()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
|
||||
}
|
||||
|
|
|
|||
62
arduino/HalMultiSensor/InterruptUtil.cpp
Executable file
62
arduino/HalMultiSensor/InterruptUtil.cpp
Executable file
|
|
@ -0,0 +1,62 @@
|
|||
#include <avr/power.h>
|
||||
#include <avr/sleep.h>
|
||||
|
||||
|
||||
void Interrupt::pinInterrupt() // here the interrupt is handled after wakeup
|
||||
{
|
||||
// execute code here after wake-up before returning to the loop() function
|
||||
// timers and code using timers (serial.print and more...) will not work here.
|
||||
// we don't really need to execute any special functions here, since we
|
||||
// just want the thing to wake up
|
||||
}
|
||||
|
||||
void Interrupt::setupInterrupt()
|
||||
{
|
||||
/*
|
||||
* The 5 different modes are:
|
||||
* SLEEP_MODE_IDLE -the least power savings
|
||||
* SLEEP_MODE_ADC
|
||||
* SLEEP_MODE_PWR_SAVE
|
||||
* SLEEP_MODE_STANDBY
|
||||
* SLEEP_MODE_PWR_DOWN -the most power savings
|
||||
*
|
||||
* For now, we want as much power savings as possible, so we
|
||||
* choose the according
|
||||
* sleep mode: SLEEP_MODE_PWR_DOWN
|
||||
*/
|
||||
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
|
||||
|
||||
sleep_enable(); // enables the sleep bit in the mcucr register
|
||||
// so sleep is possible. just a safety pin
|
||||
|
||||
/* Now it is time to enable an interrupt.
|
||||
* In the function call attachInterrupt(A, B, C)
|
||||
* A can be either 0 or 1 for interrupts on pin 2 or 3.
|
||||
* B Name of a function you want to execute at interrupt for A.
|
||||
* C Trigger mode of the interrupt pin. can be:
|
||||
* LOW a low level triggers
|
||||
* CHANGE a change in level triggers
|
||||
* RISING a rising edge of a level triggers
|
||||
* FALLING a falling edge of a level triggers
|
||||
*
|
||||
* In all but the IDLE sleep modes only LOW can be used.
|
||||
*/
|
||||
attachInterrupt(0,pinInterrupt, LOW);
|
||||
/*
|
||||
power_adc_disable();
|
||||
power_spi_disable();
|
||||
power_timer0_disable();
|
||||
power_timer1_disable();
|
||||
power_timer2_disable();
|
||||
power_twi_disable();
|
||||
*/
|
||||
sleep_mode(); // here the device is actually put to sleep!!
|
||||
// THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
|
||||
|
||||
sleep_disable(); // first thing after waking from sleep:
|
||||
// disable sleep...
|
||||
detachInterrupt(0); // disables interrupt 0 on pin 2 so the
|
||||
// wakeUpNow code will not be executed
|
||||
// during normal running time.
|
||||
power_all_enable();
|
||||
}
|
||||
13
arduino/HalMultiSensor/InterruptUtil.h
Executable file
13
arduino/HalMultiSensor/InterruptUtil.h
Executable file
|
|
@ -0,0 +1,13 @@
|
|||
#ifndef INTERRUPT_H
|
||||
#define INTERRUPT_H
|
||||
|
||||
|
||||
class INTERRUPT_H
|
||||
{
|
||||
public:
|
||||
sleep();
|
||||
private:
|
||||
pinInterrupt();
|
||||
}
|
||||
|
||||
#endif // INTERRUPT_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue