Hello I am new to playing with this arduino I'm making a ir remote project and i cannot seem to replace delay() with millis()
so i have two versions of my code one works but does not accept any other input when the code is on the delay line
and the other i tried to implement millis() but i get nothing on the serial monitor I've totally broken it and I cannot see why. I'm sure its something simple so thank you for your help in advance.
//working dont touch
#include <IRremote.h>
const int ledPin = 8; // the pin that the PC Power switch is attached to
signed long int incomingByte; // a variable to read incoming ir data into
const int RECV_PIN = 4; // Ir configs
IRrecv irrecv(RECV_PIN); // Ir configs
decode_results results; // Ir configs
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
irrecv.enableIRIn(); // Start the receiver
}
void loop() {
if (irrecv.decode(&results) > 0) {
Serial.println(results.value, DEC);
irrecv.resume(); //testing if it made any difference
incomingByte =(results.value);
Serial.println(incomingByte);
if (incomingByte == 550720173) {
Serial.println("Small button press");
digitalWrite(ledPin, LOW);
delay(4500);
digitalWrite(ledPin, HIGH);
}
irrecv.resume();
}
}
//Broken
#include <IRremote.h>
const int ledPin = 8; // the pin that the PC Power switch is attached to
signed long int incomingByte; // a variable to read incoming ir data into
const int RECV_PIN = 4; // Ir configs
IRrecv irrecv(RECV_PIN); // Ir configs
decode_results results; // Ir configs
unsigned long startMillis; //some global variables available anywhere in the program
unsigned long currentMillis;
const unsigned long period = 4500;
void setup() {
Serial.begin(115200);
pinMode(ledPin, OUTPUT); // initialize the LED pin as an output:
digitalWrite(ledPin, HIGH);
irrecv.enableIRIn(); // Start the receiver
startMillis = ; //initial start time
}
void loop() {
currentMillis = millis(); { //get the current "time" (actually the number of milliseconds since the program started)
if (irrecv.decode(&results) > 0) {
Serial.println(results.value, DEC);
irrecv.resume();
incomingByte = (results.value);
Serial.println(incomingByte);
if (currentMillis - startMillis >= period) //test whether the period has elapsed
{
if (incomingByte == 550720173) {
Serial.println("Small button press");
digitalWrite(ledPin, LOW);
}
}
digitalWrite(ledPin, HIGH);
}
irrecv.resume();
}
}