Advertisement
papuc111

Servo auf Alarmzustand zurückfahren

Mar 29th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2.  
  3. const int AlarmPin = 13;
  4. const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
  5. LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
  6.  
  7.  
  8.  
  9. // Servo Library einbinden
  10. #include <Servo.h>
  11.  
  12. // Neues Servo Objekt erstellen
  13. Servo myservo;
  14. // Wert des Potentiometers hier speichern
  15. int val;
  16.  
  17. // setup() wird einmal zu Programmbeginn ausgeführt
  18. void setup()
  19. {
  20. lcd.begin(16, 2);
  21. // Servo an Pin 9 koppeln
  22. myservo.attach(9);
  23.  
  24. // Copyright TEXT
  25. lcd.clear();
  26. lcd.setCursor(0, 0);
  27. lcd.print("Servo: ");
  28. lcd.setCursor(0, 1);
  29. lcd.print("Poti mit LCD");
  30. delay(2000);
  31. }
  32.  
  33. void loop()
  34. {
  35. // Stellung des Potentiometers an Anlog-Eingang 1 auslesen
  36. val = analogRead(1);
  37. // 10-bit Wert des Analogeingangs (0-1023) in Winkel 0-180 umrechnen
  38. val = map(val, 0, 1023, 0, 180);
  39.  
  40.  
  41. if (AlarmPin == HIGH) { // Alarm eingang high bzw. Tilt Sensor geneigt
  42.  
  43. myservo.write(0);
  44.  
  45. } else {
  46. myservo.write(val);
  47.  
  48. }
  49.  
  50.  
  51.  
  52. lcd.clear();
  53. lcd.setCursor(0, 0);
  54. lcd.print("Servomotor Position:");
  55.  
  56.  
  57. lcd.setCursor(0, 1);
  58.  
  59. lcd.print("Position:");
  60. lcd.setCursor(9, 1);
  61. lcd.print(val);
  62. lcd.setCursor(12,1);
  63. lcd.print( "\337");
  64.  
  65.  
  66.  
  67.  
  68. delay(50);
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement