Hello, I am working on a binary counter with 5 LEDs in it. I am using the millis() function so that every half an hour the LED increases a float by 0.5 in value. Each float represents a set for the coding of the binary counter. However, in the middle of the half an hour, if anytime a person pushes a toggle button, then the integer will increase in value by 0.5, causing the counter to move one number higher. The problem with my millis() function however, is that when I code readVal==0; the integer value does increase.
However, the other blocks of code propagate the condition. I want my integer value to increase evenly
like 9, push, 9.5. 9.5, push, 10. 10, push, 10.5.
However the integer value directly goes from 9 to 10.5 in a single push. How can I achieve separate timed events with the millis function?
int pin1 = 12;
int pin2 = 11;
int pin3 = 10;
int pin4 = 9;
int pin5 = 8;
int readVal;
float timE=9;
unsigned long dt1 = 180000;
unsigned long dt2 = 5760000;
unsigned long preTime=0;
void setup() {
// put your setup code here, to run once:
pinMode(A0, INPUT);
pinMode(pin1, OUTPUT);
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
pinMode(pin4, OUTPUT);
pinMode(pin5, OUTPUT);
Serial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
unsigned long curTime=millis();
Serial.print(" The time now is: ");
Serial.println(timE);
Serial.print(", ReadVal is: ");
readVal=digitalRead(A0);
Serial.println(readVal);
delay(300);
if (timE==9){
digitalWrite(pin1, LOW);
digitalWrite(pin2, LOW);
digitalWrite(pin3, LOW);
digitalWrite(pin4, LOW);
digitalWrite(pin5, HIGH);
if(readVal==0){
timE=timE+0.5;
}
if(curTime-preTime>=dt1){
timE=9.5;
preTime=curTime;
}
}
if (timE==9.5){
digitalWrite(pin1, LOW);
digitalWrite(pin2, LOW);
digitalWrite(pin3, LOW);
digitalWrite(pin4, HIGH);
digitalWrite(pin5, LOW);
if(readVal==0){
timE=timE+0.5;
}
if(curTime-preTime>=dt1){
timE=10;
preTime=curTime;
}
}
if (timE==10){
digitalWrite(pin1, LOW);
digitalWrite(pin2, LOW);
digitalWrite(pin3, LOW);
digitalWrite(pin4, HIGH);
digitalWrite(pin5, HIGH);
if(readVal==0){
timE=timE+0.5;
}
if(curTime-preTime>=dt1){
timE=timE+0.5;
preTime=curTime;
}
}
}
Thanks for your help!