Hello guys,
I'm trying to restart the loop with the remote but it doesn't even work with the code
#include <avr/wdt.h>
void softwareReset( uint8_t prescaller) {
// start watchdog with the provided prescaller
wdt_enable( prescaller);
// wait for the prescaller time to expire
// without sending the reset signal by using
// the wdt_reset() method
while(1) {}
}
void setup() { // add setup code here...}
void loop() {
// ... various code...
// restart in 60 milliseconds
softwareReset( WDTO_60MS);
}
And
void softwareReset( unsigned long delayMillis) {
uint32_t resetTime = millis() + delayMillis;
while ( resetTime > millis()) {
/* wait and do nothing until the required delay expires... */
}
// jump to the start of the program
asm volatile ( "jmp 0");
}
Here my sketch
#include <TM1637Display.h>
#include "IRremote.h"
#include <avr/wdt.h>
// Module connection pins (Digital Pins)
#define CLK 4
#define DIO 3
// The amount of time (in milliseconds) between tests
#define TEST_DELAY 1000
TM1637Display display(CLK, DIO);
boolean running = false;
int count = 600;
uint8_t data[] = {0, 0, 0, 0};
const uint8_t PLAY[] = {B01110011, B00111000, B01110111, B01101110};
const int RECV_PIN = 5;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup() {
display.setBrightness(0x0f);
pinMode(2,OUTPUT);
irrecv.enableIRIn();
irrecv.blink13(true);
display.setSegments(PLAY);
}
void loop() {
cronometro();
comeco();
}
void cronometro() {
while (running) {
data[0] = display.encodeDigit((count / 60) / 10); // Dezena de minuto
data[1] = display.encodeDigit((count / 60) % 10) | (count % 2 ? 0x80 : 0x00); // Unidade de minuto
data[2] = display.encodeDigit((count % 60) / 10); // Dezena de segundo
data[3] = display.encodeDigit((count % 60) % 10); // Unidade de segundo
display.setSegments(data);
if(count >= 0) {
count--;
} else {
}
delay(TEST_DELAY);
}
}
void comeco() {
if(irrecv.decode(&results))
{
irrecv.resume();
if( results.value == 0xFF629D )
{
running = true;
} else if( results.value == 0xFF4AB5 ) {
softwareReset( WDTO_60MS);
}
}//if
}
void softwareReset( uint8_t prescaller) {
// start watchdog with the provided prescaller
wdt_enable( prescaller);
// wait for the prescaller time to expire
// without sending the reset signal by using
// the wdt_reset() method
while(1) {}
}