Hi Folks,
Hope you are doing fine !
I spend many days tring to do a simples code run but I fail in all ways
My code should to do ......
Turn on micronctroller from mechanical switch
Send IR signal for 6 sec.
after 6 seconds go to sleeep for save battery
keep on sleep until to mechanical switch should turn off microcontroller after 30sec more or less
I tried to use IF, Were as well case switch but i think problem is using interruption + library from sleep .
Below you can find my code
Anyone know a way to help me ? I really apreciate it
int cont = 0;
#include "tinysnore.h"
void setup(){
DDRB |= (1<<PB0); //Set pin PB0 as output
TCNT0 = 0;
TCCR0A=0;
TCCR0B=0;
TCCR0A |=(1<<COM0A0); //Timer0 in toggle mode Table 11-2
TCCR0A |=(1<<WGM01); //Start timer 1 in CTC mode Table 11.5
TCCR0B |= (1 << CS00);// Prescaler table 11.6
OCR0A=104; //CTC Compare value
}
void loop(){
if (cont == 3) {
snore(30000);
} else {
TCCR0A &= ~(1<<COM0A0); //off
delay(1000);
TCCR0A |=(1<<COM0A0); //on
delay(1000);
cont++;
}
}
Hi Larry.
Hardware is working well ........ if a run my code without sleep, IR work perfect
My target is
I need just 6sec IR on and go to sleep mode until to mechanical sitch turnoff my cisrucit.
I made a simple code as below it's work perfect
void setup(){
DDRB |= (1<<PB0); //Set pin PB0 as output
TCNT0 = 0;
TCCR0A=0;
TCCR0B=0;
TCCR0A |=(1<<COM0A0); //Timer0 in toggle mode Table 11-2
TCCR0A |=(1<<WGM01); //Start timer 1 in CTC mode Table 11.5
TCCR0B |= (1 << CS00);// Prescaler table 11.6
OCR0A=104; //CTC Compare value
}
void loop(){
TCCR0A &= ~(1<<COM0A0); //off
delay(1000);
TCCR0A |=(1<<COM0A0); //on
delay(1000);
}
But it's keep runing around 40 seconds until to mechanical switch turnoff my circuit.
I would like to use IR for 6 seconds and save baterry puttin it on sleep after 6 seconds.
juliodv:
Turn on micronctroller from mechanical switch
Send IR signal for 6 sec.
after 6 seconds go to sleeep for save battery
keep on sleep until to mechanical switch should turn off microcontroller after 30sec more or less
I had no toruble with circuit.
I made it simple as below
Here is step from code.
step 1 - Turn on micronctroller from mechanical switch ..... my last topic with esquematic
step 2 - Send IR signal for 6 sec.
step 3 - after 6 seconds go to sleeep for save battery
step 4 - keep on sleep until to mechanical switch turnoff microcontroller
My mistake is .... when microcontroller turnon don't follow my code using if.
int cont = 0;
#include "tinysnore.h"
void setup(){
DDRB |= (1<<PB0); //Set pin PB0 as output
TCNT0 = 0;
TCCR0A=0;
TCCR0B=0;
TCCR0A |=(1<<COM0A0); //Timer0 in toggle mode Table 11-2
TCCR0A |=(1<<WGM01); //Start timer 1 in CTC mode Table 11.5
TCCR0B |= (1 << CS00);// Prescaler table 11.6
OCR0A=104; //CTC Compare value
}
void loop(){
if (cont == 3) {
snore(30000);
} else {
TCCR0A &= ~(1<<COM0A0); //off
delay(1000);
TCCR0A |=(1<<COM0A0); //on
delay(1000);
cont++;
}
}
I'm using mechanical switch from machine end stroke like this
it's seen a software problem like keep pin on awake 6 second send 38khz after 6 seconds sleep.
This code work perfect changing 38khz script for blink script without interrupts just to made a test.
But if I use 38khz functions doesn't work ..... don't respect my if conditions