michael_x:
Meinst du sowas?
byte minuten ; // wird über Taster eingestellt ( 0 .. theoretisch 255 )
bool stop; // true: Zeit läuft nicht, false: Zeit läuft. Wird über Taster oder bei Zeitablauf gesetzt
uint16_t sekunden; // wird, wenn stop per Taster auf false gesetzt wird, mit minuten*60 initialisiert, dann runtergezählt
void loop() {
// Taster Behandlung hier einbauen
if (stop) {
servoUP();
} else {
if (sekunden % 60 < 30) servoUP();
else servoDOWN();
if ( millis() - lastSecond >= 1000) {
// einmal pro Sekunde
lastSecond +=1000;
if (sekunden > 0) sekunden--; // im Sekundentakt bis 0 herunterzählen
else stop = true;
}
}
}
% ist die Modulo-Division ( Rest ), falls dir das zur "Eleganz" noch gefehlt haben sollte ;)
Das verstehe ich noch nicht so ganz, aber der Reihe nach und Danke schonmal 
Habe jetzt erstmal das Relais verkabelt und zum testen folgenden Code geschrieben:
digitalWrite(RECHTS,HIGH);
delay(3000);
digitalWrite(RECHTS, LOW);
digitalWrite(LINKS, HIGH);
delay(3000);
digitalWrite(LINKS, LOW);
Funktioniert so wie es soll.
Mein Problem ist gerade der StartStopButton.
Ist ja mit -1 definiert, aber wenn ich Ihn ausgeben lasse hat er 1, bei Tastendruck dann 0, bekomme es nicht hin seinen Zustand zu speichern.
Hier mal mein kompletter Code, unten könnt Ihr mein geteste sehen---
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display
#define RECHTS 7
#define LINKS 8
const int UpButton = 2;// the number of the pushbutton pin
const int DownButton = 3;// the number of the pushbutton pin
const int StartStopButton = 4;// the number of the pushbutton pin
int buttonPushCounter = 0; // counter for the number of button presses
int UpButtonState = -1;// current state of the button
int DownButtonState = -1;// current state of the button
int StartStopButtonState = -1;// current state of the button
//boolean lastButtonState = LOW;
boolean lastUpButtonState = LOW;
boolean lastDownButtonState = LOW;// previous state of the button
boolean lastStartStopButtonState = LOW;
void setup() {
lcd.init();
lcd.backlight();
lcd.setCursor(3, 0);
lcd.print("TeaMyTron");
lcd.setCursor(0, 1);
lcd.print("Minuten: 0");
pinMode(UpButton, INPUT_PULLUP);
pinMode(DownButton, INPUT_PULLUP);
pinMode(StartStopButton, INPUT_PULLUP);
pinMode(RECHTS, OUTPUT);
pinMode(LINKS, OUTPUT);
}
void loop() {
UpButtonState = digitalRead(UpButton);
if (UpButtonState != lastUpButtonState) { // Jeder Button braucht ein Last
lastUpButtonState = UpButtonState; // last merken
delay(10);
if (UpButtonState == LOW) // wegin INPUT_PULLUP
{
buttonPushCounter++;
//delay(250);
lcd.setCursor(9, 1);
lcd.print(buttonPushCounter);
}
}
DownButtonState = digitalRead(DownButton);
if (DownButtonState != lastDownButtonState) { // Jeder Button braucht ein Last
lastDownButtonState = DownButtonState; // last merken
delay(10);
if (DownButtonState == LOW) // wegin INPUT_PULLUP
{
lcd.setCursor(9, 1);
lcd.print(" ");
buttonPushCounter--;
//delay(250);
lcd.setCursor(9, 1);
lcd.print(buttonPushCounter);
}
}
if (buttonPushCounter > 10) {
buttonPushCounter = 0;
lcd.setCursor(9, 1);
lcd.print("0 ");
}
if (buttonPushCounter < 0) {
buttonPushCounter = 10;
lcd.setCursor(9, 1);
lcd.print("10 ");
}
//StartStopButtonState = digitalRead(StartStopButton);
//if ((StartStopButtonState = 0) && (buttonPushCounter = 3)) { // Jeder Button braucht ein Last
// lastStartStopButtonState = StartStopButtonState; // last merken
// delay(10);
// }
//if (StartStopButtonState == LOW) // wegin INPUT_PULLUP
//{
//StartStopButtonState = LOW;
//lcd.setCursor(14, 0);
//lcd.print("YOO");
//lcd.print(StartStopButtonState);
//}
// if (StartStopButtonState == HIGH) // wegin INPUT_PULLUP
// {
// lcd.setCursor(9, 1);
// lcd.print(" ");
// lcd.print(StartStopButtonState);
//}
digitalWrite(RECHTS,HIGH);
delay(3000);
digitalWrite(RECHTS, LOW);
digitalWrite(LINKS, HIGH);
delay(3000);
digitalWrite(LINKS, LOW);
}
Oh Mann... ratlos