/*
Button 1 = yellow : speed up direction 1
Button 2 = red : lights are not working;just oranje blink
*/
#define BUTTON_PIN 21 // GIOP21 pin connected to button
#define DEBOUNCE_TIME 50 // the debounce time in millisecond, increase this time if it still chatters
// Variables will change:
int lastSteadyState = LOW; // the previous steady state from the input pin
int lastFlickerableState = LOW; // the previous flickerable state from the input pin
int currentState; // the current reading from the input pin
// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
const int ledPinGroen1 = 25;
const int ledPinOranje1 = 26;
const int ledPinRood1 = 27;
//bool rood1 = false;
//bool groen1 = true;
//bool oranje1 = false;
const int ledPinGroen2 = 16;
const int ledPinOranje2 = 5;
const int ledPinRood2 = 17;
//bool rood2 = true;
//bool groen2 = false;
//bool oranje2 = false;
int timeOfCycle;
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// initialize the pushbutton pin as an pull-up input
// the pull-up input pin will be HIGH when the switch is open and LOW when the switch is closed.
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(ledPinGroen1, OUTPUT);
pinMode(ledPinOranje1, OUTPUT);
pinMode(ledPinRood1, OUTPUT);
pinMode(ledPinGroen2, OUTPUT);
pinMode(ledPinOranje2, OUTPUT);
pinMode(ledPinRood2, OUTPUT);
timeOfCycle = 20000;
}
void loop() {
// read the state of the switch/button:
currentState = digitalRead(BUTTON_PIN);
lightsCycle(timeOfCycle);
// check to see if you just pressed the button
// (i.e. the input went from LOW to HIGH), and you've waited long enough
// since the last press to ignore any noise:
// If the switch/button changed, due to noise or pressing:
if (currentState != lastFlickerableState) {
// reset the debouncing timer
lastDebounceTime = millis();
// save the the last flickerable state
lastFlickerableState = currentState;
}
/*
if ((millis() - lastDebounceTime) > DEBOUNCE_TIME) {
// whatever the reading is at, it's been there for longer than the debounce
// delay, so take it as the actual current state:
// if the button state has changed:
if (lastSteadyState == HIGH && currentState == LOW)
Serial.println("The button is pressed");
else if (lastSteadyState == LOW && currentState == HIGH)
Serial.println("The button is released");
if (lastSteadyState == LOW && currentState == HIGH && timeOfCycle > 5000) {
timeOfCycle = 1000;
// } else if (lastSteadyState == LOW && currentState == HIGH && timeOfCycle < 5000) {
// timeOfCycle = 8000;
//lightsCycle(timeOfCycle);
}
*/
// save the the last steady state
lastSteadyState = currentState;
// }
}
void lightsCycle(int timeOfCycle) {
// cycle1
digitalWrite(ledPinGroen2,LOW );
digitalWrite(ledPinRood2, HIGH);
digitalWrite(ledPinRood1, LOW);
digitalWrite(ledPinGroen1, HIGH);
digitalWrite(ledPinOranje1, LOW);
digitalWrite(ledPinOranje2, LOW);
delay(ceil(timeOfCycle/5*2));
//cycle2
digitalWrite(ledPinGroen1, LOW);
digitalWrite(ledPinOranje1, HIGH);
delay(ceil(timeOfCycle/5));
digitalWrite(ledPinOranje1, LOW);
digitalWrite(ledPinRood1, HIGH);
digitalWrite(ledPinGroen2, HIGH);
digitalWrite(ledPinRood2, LOW);
delay(ceil(timeOfCycle/5*2));
digitalWrite(ledPinGroen2, LOW);
digitalWrite(ledPinOranje2, HIGH);
digitalWrite(ledPinRood1, HIGH);
delay(ceil(timeOfCycle/5*2));
digitalWrite(ledPinOranje2, LOW);
digitalWrite(ledPinRood1, LOW);
digitalWrite(ledPinGroen1, HIGH);
digitalWrite(ledPinRood2, HIGH);
delay(ceil(timeOfCycle/5*2));
//
//Serial.println("aan is true naar false");
//Serial.println(rood1);
// }
}
/*
void loop() {
// read the state of the switch/button:
currentState = digitalRead(BUTTON_PIN);
if (lastState == HIGH && currentState == LOW)
{
Serial.println("The button is pressed lastState and currentState is:");
Serial.println(lastState);
Serial.println(currentState);
digitalWrite(ledPinGroen1,HIGH);
digitalWrite(ledPinOranje1, HIGH);
digitalWrite(ledPinRood1, HIGH);
delay(500);
//lastState = currentState;
}else if (lastState == LOW && currentState == HIGH)
{Serial.println("The button is released and lastState is :");
Serial.println(lastState);
Serial.println(currentState);
digitalWrite(ledPinGroen1, LOW);
digitalWrite(ledPinOranje1, LOW);
digitalWrite(ledPinRood1, LOW);
delay(500);
lastState = currentState;
}
*/