Advertisement
MR_Rednax

Untitled

Dec 4th, 2023 (edited)
1,017
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <LiquidCrystal_I2C.h>
  2. #include <Wire.h>
  3.  
  4. #define maxcars 10
  5.  
  6. const int buttonPin1 = 4; // Pin voor drukknop 1 (D4)
  7. const int buttonPin2 = 5; // Pin voor drukknop 2 (D5)
  8. int count = 10;
  9.  
  10.  
  11. LiquidCrystal_I2C lcd(0x27, 16, 2); // Initialiseer het LCD-display
  12.  
  13.  
  14. void setup() {
  15.   lcd.begin(16, 2);  // Initialiseer het LCD-display met 16 kolommen en 2 rijen
  16.   lcd.backlight();   // Schakel de achtergrondverlichting in
  17.  
  18.   pinMode(buttonPin1, INPUT_PULLUP); // Drukknop 1 als input met pull-up weerstand
  19.   pinMode(buttonPin2, INPUT_PULLUP); // Drukknop 2 als input met pull-up weerstand
  20. }
  21.  
  22. void text_print(){
  23.   lcd.setCursor(0, 0);
  24.   lcd.print("Count: ");
  25.   lcd.print(count);
  26. }
  27.  
  28. void loop() {
  29.   if(digitalRead(buttonPin1) == LOW && count <= maxcars){
  30.     count++;
  31.     lcd.clear();
  32.   }
  33.   if(digitalRead(buttonPin2) == LOW && count >= 1){
  34.     count--;
  35.     lcd.clear();
  36.   }
  37.   if (count == 0) {
  38.     lcd.setCursor(0, 0);
  39.     lcd.print("VOL!                            ");
  40.   }else{
  41.     text_print();
  42.   }
  43.   delay(400);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement