Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- int val;
- int encoder0PinA = 8;
- int encoder0PinB = 9;
- int encoder0Pos = 0;
- int encoder0PinALast = LOW;
- int n = LOW;
- int dugmePin = 10;
- int dugmeState = 0;
- int stanje = 0;
- const int rs = 2, en = 3, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
- LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
- void setup()
- // Startup poruka
- {
- pinMode(dugmePin, INPUT);
- lcd.begin(16, 2);
- pinMode (encoder0PinA, INPUT);
- pinMode (encoder0PinB, INPUT);
- lcd.print(" Welcome to ");
- lcd.setCursor(0,1);
- lcd.print(" Utepuvatch V1.0 ");
- delay(2000);
- lcd.setCursor(0,0);
- lcd.clear();
- lcd.print("Made by");
- lcd.setCursor(0,1);
- lcd.print("Aleksa and Stevan");
- delay(2000);
- lcd.clear();
- }
- // Glavni kod
- void loop()
- {
- dugmeState = digitalRead(dugmePin);
- if (dugmeState == LOW)
- {
- stanje = 10;
- }
- if (stanje == 10)
- {
- lcd.setCursor(10,0);
- lcd.print(" ");
- if (encoder0Pos > 0)
- {
- encoder0Pos --;
- lcd.setCursor(10,0);
- lcd.print(encoder0Pos);
- delay(600);
- }
- else
- {
- lcd.setCursor(0,1);
- stanje = 0;
- lcd.print(" Done ");
- delay(2000);
- lcd.setCursor(0,1);
- lcd.print("Press to start");
- }
- }
- // na dole je kod za enkoder, na gore je za posmatranje stanja dugmeta
- n = digitalRead(encoder0PinA);
- if ((encoder0PinALast == LOW) && (n == HIGH))
- {
- if (digitalRead(encoder0PinB) == LOW)
- {
- encoder0Pos--;
- if (encoder0Pos <0)
- {
- encoder0Pos = 0;
- }
- }
- else
- {
- encoder0Pos++;
- }
- lcd.setCursor(0,0);
- lcd.print("UV timer: ");
- lcd.print(" ");
- lcd.setCursor(10,0);
- lcd.print (encoder0Pos);
- lcd.setCursor(14,0);
- lcd.print("min");
- lcd.setCursor(0,1);
- lcd.print("Press to start");
- }
- encoder0PinALast = n;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement