Rev | Line | |
---|
[224] | 1 | /*
|
---|
| 2 |
|
---|
| 3 | This sketch allows the users to manage the Tian and MCU power management.
|
---|
| 4 | Users can power up or power down MIPS and MCU with an external interrupt.
|
---|
| 5 |
|
---|
| 6 | */
|
---|
| 7 |
|
---|
| 8 | #include <EnergySaving.h>
|
---|
| 9 |
|
---|
| 10 | EnergySaving nrgSave;
|
---|
| 11 |
|
---|
| 12 | #define MIPS_PIN 32 //PA28 PIN 32
|
---|
| 13 |
|
---|
| 14 | void setup()
|
---|
| 15 | {
|
---|
| 16 | pinMode(MIPS_PIN,OUTPUT);
|
---|
| 17 | digitalWrite(MIPS_PIN,HIGH);
|
---|
| 18 |
|
---|
| 19 | nrgSave.begin(WAKE_EXT_INTERRUPT, 8, wakeUp); //standby setup for external interrupts
|
---|
| 20 | }
|
---|
| 21 |
|
---|
| 22 | void loop()
|
---|
| 23 | {
|
---|
| 24 | doSomething();
|
---|
| 25 | sleep();
|
---|
| 26 | }
|
---|
| 27 |
|
---|
| 28 | void doSomething(){
|
---|
| 29 | //blink for 90 seconds
|
---|
| 30 | for(int i=0; i<90; i++)
|
---|
| 31 | {
|
---|
| 32 | digitalWrite(13,HIGH);
|
---|
| 33 | delay(500);
|
---|
| 34 | digitalWrite(13,LOW);
|
---|
| 35 | delay(500);
|
---|
| 36 | }
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | void sleep(void){
|
---|
| 40 | digitalWrite(MIPS_PIN, LOW);
|
---|
| 41 | nrgSave.standby(); //now mcu goes in standby mode
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | void wakeUp(void) //interrupt routine (isn't necessary to execute any tasks in this routine
|
---|
| 45 | {
|
---|
| 46 | //mcu is waked-up by the interrupt
|
---|
| 47 |
|
---|
| 48 | //wake up mips
|
---|
| 49 | digitalWrite(MIPS_PIN,HIGH);
|
---|
| 50 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.