Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <RCSwitch.h>
- RCSwitch mySwitch = RCSwitch();
- // set pin numbers:
- const int redPin = 13;// the number of the red LED pin
- const int yellowPin = 12;// the number of the yellow LED pin
- const int greenPin = 11;// the number of the green LED pin
- const int red2Pin = 10;// the number of the red LED pin
- const int yellow2Pin = 9;// the number of the yellow LED pin
- const int green2Pin = 8;// the number of the green LED pin
- // Variables will change:
- String code;
- int flag = 0;
- int redState = LOW;// redState used to set the red LED
- int yellowState = LOW;// yellowState used to set the yellow LED
- int greenState = LOW;// greenState used to set the green LED
- int red2State = LOW;// redState used to set the red LED
- int yellow2State = LOW;// yellowState used to set the yellow LED
- int green2State = LOW;// greenState used to set the green LED
- unsigned long StartTime = 0;// will store last time the traffic sequence was started
- unsigned long CheckTime;
- unsigned long elapsedTime;
- // the follow variables is a long because the time, measured in miliseconds,
- // will quickly become a bigger number than can be stored in an int.
- long interval = 6000;// sequence interval is the time in miliseconds from the start of the green
- // light to the end of the red (milliseconds)
- void setup() {
- Serial.begin(9600);
- mySwitch.enableReceive(0); // Receiver on interrupt 0 => that is pin #2
- // set the digital pin as output:
- pinMode(redPin, OUTPUT);
- pinMode(yellowPin, OUTPUT);
- pinMode(greenPin, OUTPUT);
- pinMode(red2Pin, OUTPUT);
- pinMode(yellow2Pin, OUTPUT);
- pinMode(green2Pin, OUTPUT);
- digitalWrite(redPin, 1);
- digitalWrite(yellowPin, 1);
- digitalWrite(greenPin, 1);
- digitalWrite(red2Pin, 1);
- digitalWrite(yellow2Pin, 1);
- digitalWrite(green2Pin, 1);
- delay(2000);
- }
- void loop() {
- if (mySwitch.available()) {
- code = mySwitch.getReceivedValue();
- Serial.print("Received ");
- Serial.println( code );
- if (code == "11836946") {
- Serial.println("Open Green for 10 Seconds");
- flag = 1;
- }
- mySwitch.resetAvailable();
- }
- if (flag == 0) {
- normalOperation();
- }
- else if (flag == 1) {
- if (greenState) {
- delay(1000);
- digitalWrite(redPin, LOW);
- digitalWrite(greenPin, LOW);
- digitalWrite(yellowPin, HIGH);
- delay(1000);
- digitalWrite(greenPin, LOW);
- digitalWrite(yellowPin, LOW);
- digitalWrite(redPin, HIGH);
- digitalWrite(green2Pin, HIGH);
- digitalWrite(red2Pin, LOW);
- digitalWrite(yellow2Pin, LOW);
- delay(10000);
- digitalWrite(yellow2Pin, HIGH);
- digitalWrite(green2Pin, LOW);
- digitalWrite(red2Pin, LOW);
- delay(1000);
- flag = 0;
- }
- if (yellowState) {
- delay(1000);
- digitalWrite(redPin, HIGH);
- digitalWrite(greenPin, LOW);
- digitalWrite(yellowPin, LOW);
- digitalWrite(green2Pin, HIGH);
- digitalWrite(red2Pin, LOW);
- digitalWrite(yellow2Pin, LOW);
- delay(10000);
- digitalWrite(yellow2Pin, HIGH);
- digitalWrite(green2Pin, LOW);
- digitalWrite(red2Pin, LOW);
- delay(1000);
- flag = 0;
- }
- if (redState) {
- delay(10000);
- digitalWrite(yellow2Pin, HIGH);
- digitalWrite(green2Pin, LOW);
- digitalWrite(red2Pin, LOW);
- delay(1000);
- flag = 0;
- }
- }
- }// end of LOOP
- void normalOperation() {
- CheckTime = millis();
- elapsedTime = CheckTime - StartTime;
- if (elapsedTime > interval) {
- StartTime = CheckTime;
- }
- if (elapsedTime < 2000) {
- redState = LOW;
- yellowState = LOW;
- greenState = HIGH;
- red2State = HIGH;
- yellow2State = LOW;
- green2State = LOW;
- }
- if (elapsedTime > 2000 && elapsedTime < 3000 ) {
- redState = LOW;
- yellowState = HIGH;
- greenState = LOW ;
- red2State = HIGH;
- yellow2State = LOW;
- green2State = LOW;
- }
- if (elapsedTime > 3000 && elapsedTime < 5000) {
- redState = HIGH;
- yellowState = LOW;
- greenState = LOW ;
- red2State = LOW;
- yellow2State = LOW;
- green2State = HIGH;
- }
- if (elapsedTime > 5000 && elapsedTime < 6000) {
- redState = HIGH;
- yellowState = LOW;
- greenState = LOW ;
- red2State = LOW;
- yellow2State = HIGH;
- green2State = LOW;
- }
- digitalWrite(redPin, redState);
- digitalWrite(greenPin, greenState);
- digitalWrite(yellowPin, yellowState);
- digitalWrite(red2Pin, red2State);
- digitalWrite(green2Pin, green2State);
- digitalWrite(yellow2Pin, yellow2State);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement