na początek zaznaczę, że dopiero zaczynam przygodę z Arduino po długim czasie przerwy z programowaniem :)
mam problem z przerzutnikiem bistabilnym. Znalazłem kod opisujący taki przerzutnik i uruchomiłem go. Działał. Ponieważ do projektu potrzebuje trzech sztuk (sterowanie światłem przy łóżku) więc skopiowałem i stworzyłem drugą sekcję. również zadziałało. Przy trzeciej sekcji zaczęły się problemy. Trzecia sekcja zaczyna lekko mówiąc świrować... wyjście generuje prostokąt ( dioda mruga z tą samą częstotliwością) a sekcja pierwsza i druga nie reaguje na przełączniki. po wyłączeniu trzeciej (/*...*/) sekcji i przeładowaniu wszystko wraca do normy...
Kod: Zaznacz cały
[int in0 = 0; // the number of the input pin
int in1 = 1; // the number of the input pin
int in2 = 2; // the number of the input pin
int Out10 = 10; // the number of the output pin
int Out11 = 11; // the number of the output pin
int Out12 = 12; // the number of the output pin
int state = LOW; // the current state of the output pin
int reading; // the current reading from the input pin
int previous = HIGH; // the previous reading from the input pin
int state1 = LOW; // the current state of the output pin
int reading1; // the current reading from the input pin
int previous1 = HIGH; // the previous reading from the input pin
int state2 = LOW; // the current state of the output pin
int reading2; // the current reading from the input pin
int previous2 = HIGH; // the previous reading from the input pin
// the follow variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.
long time = 0; // the last time the output pin was toggled
long debounce = 200; // the debounce time, increase if the output flickers
void setup()
{
pinMode(in0, INPUT);
pinMode(Out10, OUTPUT);
pinMode(in1, INPUT);
pinMode(Out11, OUTPUT);
pinMode(in2, INPUT);
pinMode(Out12, OUTPUT);
}
void loop()
{
//first switch section
reading = digitalRead(in0);
if (reading == HIGH && previous == LOW && millis() - time > debounce) {
if (state == HIGH)
state = LOW;
else
state = HIGH;
time = millis();
}
digitalWrite(Out10, state);
previous = reading;
//second switch section
reading1 = digitalRead(in1);
if (reading1 == HIGH && previous1 == LOW && millis() - time > debounce) {
if (state1 == HIGH)
state1 = LOW;
else
state1 = HIGH;
// time = millis();
}
digitalWrite(Out11, state1);
previous1 = reading1;
/* //third switch section
reading2 = digitalRead(in2);
if (reading2 == HIGH && previous2 == LOW && millis() - time > debounce) {
if (state2 == HIGH)
state2 = LOW;
else
state2 = HIGH;
time = millis();
}
digitalWrite(Out12, state2);
previous2 = reading2;*/
}]
Kod w załączeniu, a jeżeli potrzebny schemat to przerysuję.