Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- #include <TimerOne.h>
- LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
- const int pinADC = A5;
- const int pinSW1 = 8;
- const int pinSW2 = 2;
- volatile bool trybCykliczny = false;
- volatile bool zmianaTrybu = false;
- void wyswietlNapiece() {
- int adcValue = analogRead(pinADC);
- float voltage = adcValue * (5.0 / 1023.0);
- lcd.setCursor(0, 1);
- lcd.print("U: ");
- lcd.print(voltage, 2);
- lcd.print(" V ");
- }
- void isrSW2() {
- wyswietlNapiece();
- }
- void isrTimer() {
- wyswietlNapiece();
- }
- void isrSW1() {
- trybCykliczny = !trybCykliczny;
- zmianaTrybu = true;
- }
- void setup() {
- lcd.begin(16, 2);
- lcd.print("Tryb: ZAD 2");
- pinMode(pinSW1, INPUT_PULLUP);
- pinMode(pinSW2, INPUT_PULLUP);
- attachInterrupt(digitalPinToInterrupt(pinSW2), isrSW2, FALLING);
- attachInterrupt(digitalPinToInterrupt(pinSW1), isrSW1, FALLING);
- }
- void loop() {
- if (zmianaTrybu) {
- zmianaTrybu = false;
- if (trybCykliczny) {
- lcd.clear();
- lcd.print("Tryb: ZAD 3");
- Timer1.initialize(500000); // 0.5s = 500000us
- Timer1.attachInterrupt(isrTimer);
- } else {
- lcd.clear();
- lcd.print("Tryb: ZAD 2");
- Timer1.detachInterrupt();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment