Hi Forum members
I have code I have been writing for a project which has been working OK but due to a delay of 2000 I have problems with a lag in activations that need to be almost instant.
The problem i am having is writing the correct code to swap the delay for millis() I just cant get it to work.
The current simplified code which works using delay(2000) is as below works but delay (2000) is what I need to swap with millis()
Rather than me muddying the water with what I have already tried any support would be a great help.
/*
AnalogReadSerial
Reads an analog input on pin 0, prints the result to the serial monitor.
Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
*/
int ledPinl = 10; // The LED is connected to digital pin 10 actually multimeter
const int PIEZO_PINL= A3; // Piezo output
int valL=0;
int valR=0;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// initialize digital pin 10 and 11 as an output.
pinMode(10, OUTPUT);
analogWrite (ledPinl, 127);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input on analog pin 3:
int sensorValue00 = analogRead(A3);
Serial.print(", Sensor Value 00: ");
Serial.println(sensorValue00);
delay(100); // delay in between reads for stability
// read the input on analog pin 4:
int sensorValue01 = analogRead(A4);
// if the analog value is high enough, turn on the LED:
// print out the value you read:
Serial.print(", Sensor Value 01: ");
Serial.println(sensorValue01);
delay(100); // delay in between reads for stability
int valL = analogRead(A3);
if (valL < 10){
if (sensorValue01 > valL) // if the current state is below 01 turns on Right LED
analogWrite(ledPinl, 255);
delay(2000);
analogWrite(ledPinl, 127);
}