Kurze Problemstellung :
Ich habe hier ein Arduino Mega Board und möchte mit einem Taster,dass
mein Programm 1x ausgeführt wird !
Mein Problem ist nur, dass der Sketch einfach nicht auf den Tastendruck
ausgeführt wird ?
Hier mal der Sketch, kann mir einer sagen wo der Fehler hängt ?
Gruß
Tim
####################
#include "OneButton.h"
const int vanillesirup=47;
const int Wodka=30;
const int Mangosaft=13; // ist als Wasser deklariert
const int Maracujasaft=48;
const int taster=2;
int ledState = LOW;
void setup() {
pinMode(vanillesirup, OUTPUT);
pinMode(Wodka, OUTPUT);
pinMode(Mangosaft, OUTPUT);
pinMode(Maracujasaft, OUTPUT);
pinMode(taster, INPUT);
}
boolean executed=false;
void loop() {
if (executed==false){
executed=true;
if (digitalRead(taster) == HIGH) {
}
digitalWrite(vanillesirup, HIGH); // turn the on (HIGH is the
voltage level)
delay (500); // vanillesirup 2 CL 1 sec.
digitalWrite(vanillesirup, LOW);
digitalWrite(Wodka, HIGH); // turn the on (HIGH is the voltage
level)
delay (500); // Wodka 2 CL 1 sec.
digitalWrite(Wodka, LOW);
digitalWrite(Mangosaft, HIGH); // turn the on (HIGH is the
voltage level)
delay (1000); // 2CL 1 sec.
digitalWrite(Mangosaft, LOW);
digitalWrite(Maracujasaft, HIGH); // turn the on (HIGH is the
voltage level)
delay (1000); // 2CL 1 sec.
digitalWrite(Maracujasaft, LOW);
delay(5);
}
else
{
digitalWrite(vanillesirup,LOW);
digitalWrite(Wodka,LOW);
digitalWrite(Mangosaft,LOW);
{
}
}
}
#####################################
Moin, bitte schreibe alles in die passenden Formatierungen und einrücken nicht vergessen. Dies wird auch nur 1x ausgeführt...
1 | if (executed==false){ |
2 | executed=true; |
3 | if (digitalRead(taster) == HIGH) {} |
4 | |
5 | ..
|
6 | }
|
Also stimmt deine hier Logik nicht.
acetim@t-online.de tom schrieb: > Mein Problem ist nur, dass der Sketch einfach nicht auf den Tastendruck > ausgeführt wird ? In der Loop könnte man es so lösen:
1 | void loop() |
2 | {
|
3 | static int button_old = LOW; |
4 | int button_new = digitalRead(taster); |
5 | //If rising edge
|
6 | if(button_new == HIGH && button_old == LOW) |
7 | {
|
8 | // Mix cocktail?
|
9 | }
|
10 | button_old = button_new; |
11 | }
|
Ich habe eine Flankenerkennung eingebaut, dass das Programm nicht dauernd wiederholt wird wenn man den Taster gedrückt lässt.
Gibt es denn in der Arduino-Lib keine fertige Entprellfunktion? Das macht vieles einfacher.
Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.