Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x27, 16, 2);
- int green = 5;
- int red = 6;
- int yellow = 7;
- int pass = 2;
- int fail = 3;
- int Emergency = 4;
- int buzzer = 8;
- int B = 0; // batch counter
- int p = 0; // pass counter
- int f = 0; // fail counter
- bool isInEmergency = false;
- void setup()
- {
- pinMode(green, OUTPUT); // here i am declaring the pinMode for each componant
- pinMode(red, OUTPUT);
- pinMode(yellow, OUTPUT);
- pinMode(pass, INPUT);
- pinMode(fail, INPUT);
- pinMode(Emergency, INPUT);
- pinMode(buzzer, OUTPUT);
- lcd.init(); // I am now coding what the LCD should display in order for the Counter to work
- lcd.backlight();
- lcd.setCursor(0, 0);
- lcd.print("Pass: ");
- lcd.setCursor(9, 0);
- lcd.print("Fail: ");
- lcd.setCursor(4, 1);
- lcd.print("Batch: ");
- }
- bool lastButtonState = false;
- void loop()
- {
- bool newButtonState = digitalRead(Emergency);
- if (newButtonState != lastButtonState)
- {
- // react to the initial pressing of the button, which is
- // when it goes HIGH
- if (newButtonState == HIGH)
- {
- // the emergency button has been pressed, so we need to flip its state.
- // check if we're transitioning from a no-emergency to emergency or reverse
- // check previous state
- if (isInEmergency)
- {
- // new state after flipping
- isInEmergency = false;
- // emergency has been removed, reprint counters
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Pass: ");
- lcd.print(p);
- lcd.setCursor(9, 0);
- lcd.print("Fail: ");
- lcd.print(f);
- lcd.setCursor(4, 1);
- lcd.print("Batch: ");
- lcd.print(B);
- }
- else
- {
- // we just entered an emergency.
- isInEmergency = true;
- lcd.clear(); // clear everything off the screen
- lcd.setCursor(0, 0);
- lcd.println("EMERGENCY");
- }
- // debounce button
- delay(250);
- }
- }
- lastButtonState = newButtonState;
- // stop further execution of this function if we're in an emergency.
- // will prompt to re-check the emergency button in the next loop.
- if (isInEmergency)
- return;
- // check if the pass button has been pressed (HIGH)
- if (digitalRead(pass))
- {
- // increase global pass counter
- p++;
- // update LCD screen
- lcd.setCursor(5, 0);
- lcd.print(p);
- // have we reached 10 passes => 1 batch?
- if (p == 10)
- {
- // increase number of batches
- B++;
- // reset number of passes
- p = 0;
- // update LCD regarding batches and passes
- lcd.setCursor(10, 1);
- lcd.print(B);
- lcd.setCursor(5, 0);
- lcd.print(p);
- }
- // debounce
- delay(250);
- }
- // check if the "fail" button was pressed
- if (digitalRead(fail))
- {
- f++; // increase global variable for fail count
- // update LCD
- lcd.setCursor(14, 0);
- lcd.print(f);
- // debounce
- delay(250);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement