Untitled
unknown
plain_text
2 months ago
2.0 kB
3
Indexable
#include <Servo.h> #include <Wire.h> #include <Adafruit_LiquidCrystal.h> Servo servo_9; int servoKot = 70; Adafruit_LiquidCrystal lcd(0); const int buttonPin = 2; bool programActive = false; unsigned long lastDebounceTime = 0; const unsigned long debounceDelay = 50; void setup() { pinMode(buttonPin, INPUT_PULLUP); Serial.begin(9600); servo_9.attach(9); lcd.begin(16, 2); lcd.setBacklight(LOW); lcd.setCursor(0, 0); lcd.print("\x8ean Pantek, 3R2"); lcd.setCursor(0, 1); lcd.print("Datum: 13.1.2025"); delay(2000); lcd.clear(); } void loop() { static bool buttonState = HIGH; static bool lastButtonState = HIGH; int reading = digitalRead(buttonPin); if (reading != lastButtonState) { lastDebounceTime = millis(); } if ((millis() - lastDebounceTime) > debounceDelay) { if (reading != buttonState) { buttonState = reading; if (buttonState == LOW && !programActive) { programActive = true; lcd.clear(); lcd.setCursor(0, 0); lcd.print("Program zagnan"); delay(2000); lcd.clear(); } } } lastButtonState = reading; if (!programActive) { return; } for (servoKot = 70; servoKot <= 210; servoKot += 5) { servo_9.write(servoKot); Serial.print("Servo: "); Serial.print(servoKot); Serial.println(" stopinj"); if (servoKot % 10 == 0) { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Servo kot:"); lcd.setCursor(0, 1); lcd.print(servoKot); lcd.print(" stopinj"); } delay(20); } delay(2000); for (servoKot = 210; servoKot >= 70; servoKot -= 5) { servo_9.write(servoKot); Serial.print("Servo: "); Serial.print(servoKot); Serial.println(" stopinj"); if (servoKot % 10 == 0) { lcd.clear(); lcd.setCursor(0, 0); lcd.print("Servo kot:"); lcd.setCursor(0, 1); lcd.print(servoKot); lcd.print(" stopinj"); } delay(20); } delay(2000); }
Editor is loading...
Leave a Comment