/* Test Garagentor ATMega328p I2C-Display mit Backpack-Modul Saintsmart, Funduino u.a. 20x4 Display NewLiquidCrystal_I2C Library verwendet, Orig. LiquidCrystal_I2C und LiquidCrystal in anderen Ordner verschieben oder löschen! (Vorher sichern.) */ #include #include // (uint8_t lcd_Addr, uint8_t En, uint8_t Rw, uint8_t Rs, uint8_t d4, uint8_t d5, uint8_t d6, uint8_t d7, uint8_t backlighPin, t_backlighPol pol) LiquidCrystal_I2C lcd(0x20,2,1,0,4,5,6,7,3,POSITIVE); // Funduino I2C-LCD // Garagentor Motor const byte Motor_A_Pin = 9; const byte Motor_B_Pin = 10; const byte buttonPin1 = 2; // pin 4 Garagetor Auf const byte buttonPin2 = 3; // pin 5 Garagetor Zu #define analogPin A0 // pin 23 Servomotor Strommessung Analogeingang für Motorstop int val = 0; unsigned long time; void setup () { Wire.begin(); Serial.begin(9600); lcd.begin(20,4); lcd.clear(); lcd.backlight(); lcd.print("Test Garage"); pinMode(8, OUTPUT); // Led // Garagentor Motor pinMode(Motor_A_Pin, OUTPUT); pinMode(Motor_B_Pin, OUTPUT); pinMode(buttonPin1, INPUT); // Taster: Garage Auf pinMode(buttonPin2, INPUT); // Taster: Garage Zu digitalWrite(Motor_A_Pin,LOW); // Motor aus digitalWrite(Motor_B_Pin,LOW); // Motor aus }//Ende Setup void loop () { lcd.setCursor(0, 1); lcd.print("Val: "); lcd.print(analogRead(analogPin)); lcd.print(" "); if (digitalRead(buttonPin1)==1) { Garage_auf(); // Garage = auf; delay(200); } if (digitalRead(buttonPin2)==1) { Garage_zu(); // Garage = zu; delay(200); } }//Ende Loop // Garage auf/zu millis() fehlt noch void Garage_auf() { Serial.println("Garage geht auf "); digitalWrite(Motor_A_Pin,HIGH); // Motor ein --> Garage geht auf byte motor = 1; time = millis(); int timeout = 4000; // 4 Sekunden while ( motor>0 ) { // Endschalter-Abfrage fehlt noch val = analogRead(analogPin); // read the input pin lcd.setCursor(5, 1); lcd.print(val); lcd.print(" "); if ((millis()-time) > timeout) motor=0; if (val > 200) motor=0; // Strom > 100mA , Motor blockiert } digitalWrite(Motor_A_Pin,LOW); // Motor aus Serial.println("Garage = auf "); } void Garage_zu() { Serial.println("Garage geht zu "); digitalWrite(Motor_B_Pin,HIGH); // Motor ein --> Garage geht zu byte motor = 1; time = millis(); int timeout = 4000; while ( motor>0 ) { // Endschalter fehlt noch val = analogRead(analogPin); // read the input pin lcd.setCursor(5, 1); lcd.print(val); lcd.print(" "); if ((millis()-time) > timeout) motor=0; if (val > 200) motor=0; // Strom > 100mA , Motor blockiert } digitalWrite(Motor_B_Pin,LOW); // Motor aus Serial.println("Garage = zu "); }