This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
lab6 [2014/11/11 16:41] dan.tudose |
lab6 [2018/11/08 22:13] (current) dan.tudose |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Sleep, Low Power și Sincronizare ====== | ====== Sleep, Low Power și Sincronizare ====== | ||
- | Codul pentru bilbioteca ZigduinoSleep | + | Codul din laboratoarele anterioare transmitea periodic pachete de date în rețea dar, în intervalele de timp dintre două transmisiuni succesive, cicla inutil. Acest lucru duce la un consum de energie ridicat, ce poate avea un impact semnificativ asupra timpului de viață al nodului senzorial în cazul în care acesta este alimentat |
- | <code C> | + | Din acest motiv, este preferabil ca nodurile să intre într-o stare de low-power în momentele de inactivitate. Pentru aceasta, veți folosi o biblioteca SparrowSleep. |
- | /* | + | |
- | Blink | + | |
- | Turns on an LED on for one second, then off for one second, repeatedly. | + | |
- | + | ||
- | This example code is in the public domain. | + | |
- | */ | + | |
- | + | ||
- | // Pin 13 has an LED connected on most Arduino boards. | + | |
- | // give it a name: | + | |
- | #include <avr/sleep.h> | + | Codul pentru biblioteca SparrowSleep poate fi descărcat de [[https://github.com/ |
- | #include <avr/interrupt.h> | + | |
- | #include < | + | |
- | int led = 11; | + | Pentru a testa modul de sleep, putem folosi exemplul de mai jos: |
- | int state = 0; | + | |
- | void setup() { | + | <code C> |
- | + | ||
- | pinMode(led, | + | |
+ | /* This is an example for SparrowVSleep library. | ||
+ | You need to call SparrowV_SleepInit function. | ||
+ | The funciton has 2 params. | ||
+ | 1st param: integer (> 1 second, greater than 1 second) (represent time in seconds, how long the board will sleep) | ||
+ | 2nd param: bool (true - with data retention, false - with no data retention) | ||
+ | In case of no data retention the board can sleep max 8 secons and it will | ||
+ | reboot after time end. | ||
+ | */ | ||
+ | |||
+ | #include < | ||
+ | |||
+ | void setup() { | ||
Serial.begin(9600); | Serial.begin(9600); | ||
- | Serial.println(" | ||
- | | ||
- | ZigduinoSleepInit(); | ||
} | } | ||
void loop() { | void loop() { | ||
- | | + | // put your main code here, to run repeatedly: |
- | + | | |
- | //Code that is executed before sleep | + | |
- | state ^= 1; | + | Serial.flush(); |
- | if(state == 0) digitalWrite(led, HIGH); | + | |
- | else digitalWrite(led, LOW); | + | //sleep for 25 seconds with data retention |
- | | + | SparrowV_SleepInit(25, true); |
- | | + | |
- | | + | Serial.println(" |
- | | + | Serial. println(" |
- | | + | Serial. |
- | + | Serial.flush(); | |
- | //End of code | + | delay(5000); |
- | + | ||
- | | + | |
- | + | ||
} | } | ||
</ | </ | ||
+ | |||
+ | < | ||
+ | < | ||
+ | < |