i try to make a code for saving energy in arduino by using IDLE MODE...
i used timer 2 for give an intteruption to my processeur every 6s...
but my problem is,how i can make a mesure to verify that my code is correct???
can someone help me please....
thanks...
#include <Timer.h> #include <avr/sleep.h>
const int ledPin=13 ; //declarer le port 13 comme output
int iEtat ;
TIMER TIM = TIMER(); //instancier la class de la TEMPS
void setup() {
pinMode (ledPin,OUTPUT);
iEtat = 0 ; //initialise à 0
digitalWrite (ledPin,iEtat); //ecrire la valeur iEtat à broche 13
TIM.Init() ; //appelle la fonction donc la biblio
TIM.Stop() ; //appelle la fonction donc la biblio
TIM.Set(6000) ; //appelle la fonction donc la biblio
TIM.Start() ;
set_sleep_mode(SLEEP_MODE_IDLE); // sleep mode is set here
sleep_enable(); //appelle la fonction donc la biblio
}
placing an ampmeter reading the current taken by the arduino will let you know if your code is doing something.
Regarding the code, I have no idea if it'll work since I haven't seen how the TIMER class is built. But I suspect that it won't work since it should need an interrupt function to be called every 6s (or when the timer expires). But again, I have no idea if this is the case.
Usually you would be using energy saving features when your project has to run off batteries. Put the current meter between the + side of the battery and here the battery connects to the Arduino, typically the Vin pin, +5 pin, or the power jack.
Search for "sleep_cpu" and you will find a good deal of material.
You will find that SLEEP_MODE_IDLE will be woken up by any interrupt, including the timer0 one, which will fire every 1,000 microseconds. Even so, sleeping the CPU will make your main loop run at a thousand loops/sec rather than a million plus. The energy savings might well be worth it.