Im working on a project which involves a parallel assembly line so when both sensors are triggered, it triggers a new chain of events. in terms of leds, i have a white, a blue, and the third a green. If you trigger both white, and blue, green should illuminate. However, if you trigger white then blue, it works as it should, however if you trigger blue then white it does not
im really lost on this one. please excuse the sloppy programming, im really new at this
const byte BUTTON=7;
const byte BUTTON1=9;
const byte LED=3; //blue
const byte LED1=13; // white
int LED2=12;//green
int val = 0;
int val1 = 1;
unsigned long buttonPushedMillis;
unsigned long ledTurnedOnAt;
unsigned long turnOnDelay = 0;
unsigned long turnOffDelay = 2000;
unsigned long buttonPushedMillis1;
unsigned long ledTurnedOnAt1;
unsigned long turnOnDelay1 = 2000;
unsigned long turnOffDelay1 = 10;
bool ledReady = false;
bool ledState = false;
bool ledReady1 = false;
bool ledState1 = false;
void setup() {
pinMode(BUTTON, INPUT_PULLUP);
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
pinMode(BUTTON1, INPUT_PULLUP);
pinMode(LED1, OUTPUT);
digitalWrite(LED1, LOW);
pinMode(BUTTON, INPUT_PULLUP);
pinMode(LED, OUTPUT);
digitalWrite(LED, LOW);
pinMode(BUTTON1, INPUT_PULLUP);
pinMode(LED1, OUTPUT);
digitalWrite(LED1, LOW);
pinMode(LED2, OUTPUT);
}
void loop() {
unsigned long currentMillis = millis();
unsigned long currentMillis1 = millis();
if (digitalRead(BUTTON) == LOW) {
buttonPushedMillis = currentMillis;
ledReady = true;
}
{
if (ledReady) {
if ((unsigned long)(currentMillis - buttonPushedMillis) >= turnOnDelay) {
digitalWrite(LED, HIGH);
ledState = true;
ledTurnedOnAt = currentMillis;
ledReady = false;
}
}
if (ledState) {
if ((unsigned long)(currentMillis - ledTurnedOnAt) >= turnOffDelay) {
ledState = false;
digitalWrite(LED, LOW);
}
}
{
if (digitalRead(BUTTON1) == LOW) {
buttonPushedMillis1 = currentMillis1;
ledReady1 = true;
}
{
if (ledReady1) {
//this is typical millis code here:
if ((unsigned long)(currentMillis1 - buttonPushedMillis1) >= turnOnDelay1) {
digitalWrite(LED1, LOW);
ledState1 = true;
ledTurnedOnAt1 = currentMillis1;
ledReady1 = false;
}
if (ledState1) {
if ((unsigned long)(currentMillis1 - ledTurnedOnAt1) >= turnOffDelay1) {
ledState1 = false;
digitalWrite(LED1, HIGH);
val = digitalRead(3);
val1 = digitalRead(13);
if (val == val1) {
digitalWrite(LED2, HIGH);
delay(2000);
digitalWrite(LED2, LOW);
}
}
} }
}
}
}
}