Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //motojic288
- #define REMOTEXY_MODE__WIFI_CLOUD
- #include <WiFi.h>
- // RemoteXY connection settings
- #define REMOTEXY_WIFI_SSID "BS Home1"
- #define REMOTEXY_WIFI_PASSWORD "0554418546"
- #define REMOTEXY_CLOUD_SERVER "cloud.remotexy.com"
- #define REMOTEXY_CLOUD_PORT 6376
- #define REMOTEXY_CLOUD_TOKEN "6241965ea2c1223521878674596b2e72"
- #include <RemoteXY.h>
- // RemoteXY GUI configuration
- #pragma pack(push, 1)
- uint8_t RemoteXY_CONF[] = // 145 bytes
- { 255, 3, 0, 0, 0, 138, 0, 19, 0, 0, 0, 87, 105, 70, 105, 32, 67, 111, 110, 116,
- 114, 111, 108, 108, 101, 100, 32, 84, 114, 97, 102, 102, 105, 99, 32, 76, 105, 103, 104, 116,
- 0, 31, 1, 106, 200, 1, 1, 3, 0, 1, 28, 6, 51, 51, 0, 1, 8, 78, 111, 114,
- 109, 97, 108, 32, 84, 114, 97, 102, 102, 105, 99, 32, 76, 105, 103, 104, 116, 115, 0, 1,
- 27, 58, 52, 52, 0, 94, 8, 84, 114, 97, 102, 102, 105, 99, 32, 76, 105, 103, 104, 116,
- 32, 49, 32, 105, 115, 32, 71, 114, 101, 101, 110, 0, 1, 27, 111, 51, 51, 0, 120, 8,
- 84, 114, 97, 102, 102, 105, 99, 32, 76, 105, 103, 104, 116, 32, 50, 32, 105, 115, 32, 71,
- 114, 101, 101, 110, 0
- };
- // this structure defines all the variables and events of your control interface
- struct {
- // input variables
- uint8_t button_01; // =1 if button pressed, else =0
- uint8_t button_02; // =1 if button pressed, else =0
- uint8_t button_03; // =1 if button pressed, else =0
- // other variable
- uint8_t connect_flag; // =1 if wire connected, else =0
- } RemoteXY;
- #pragma pack(pop)
- int flagg =1;
- #define red1Pin 13
- #define yellow1Pin 12
- #define green1Pin 14
- #define red2Pin 27
- #define yellow2Pin 26
- #define green2Pin 25
- int state_input1 = 0;
- int state_input2 = 0;
- int state_input3 = 0;
- unsigned long currentMillis = 0;
- unsigned long previousMillis1 = 0;
- unsigned long previousMillis2 = 0;
- unsigned long previousMillis3 = 0;
- const long interval1 = 2000;
- const long interval2 = 2000;
- const long interval3 = 2000;
- int i = 0;
- int j = 0;
- enum TrafficLightState {
- RED,
- GREEN,
- YELLOW
- };
- TrafficLightState lightState1 = RED;
- TrafficLightState lightState2 = RED;
- void setupInputsOutputs() {
- pinMode(red1Pin, OUTPUT);
- pinMode(yellow1Pin, OUTPUT);
- pinMode(green1Pin, OUTPUT);
- pinMode(red2Pin, OUTPUT);
- pinMode(yellow2Pin, OUTPUT);
- pinMode(green2Pin, OUTPUT);
- }
- void turnAllLightsRED() {
- digitalWrite(red1Pin, HIGH);
- digitalWrite(yellow1Pin, LOW);
- digitalWrite(green1Pin, LOW);
- digitalWrite(red2Pin, HIGH);
- digitalWrite(yellow2Pin, LOW);
- digitalWrite(green2Pin, LOW);
- }
- void trafficLightControl(int redPin, int yellowPin, int greenPin, TrafficLightState ¤tState, unsigned long &previousMillis, unsigned long currentMillis, long interval) {
- switch (currentState) {
- case RED:
- digitalWrite(redPin, HIGH);
- digitalWrite(yellowPin, LOW);
- digitalWrite(greenPin, LOW);
- if (currentMillis - previousMillis >= interval) {
- currentState = GREEN;
- previousMillis = currentMillis;
- }
- if (j == 1) {
- i = i + 1;
- j = 0;
- }
- if (i == 2)i = 0;
- break;
- case GREEN:
- digitalWrite(redPin, LOW);
- digitalWrite(yellowPin, LOW);
- digitalWrite(greenPin, HIGH);
- if (currentMillis - previousMillis >= interval) {
- currentState = YELLOW;
- previousMillis = currentMillis;
- }
- break;
- case YELLOW:
- digitalWrite(redPin, LOW);
- digitalWrite(yellowPin, HIGH);
- digitalWrite(greenPin, LOW);
- if (currentMillis - previousMillis >= interval) {
- currentState = RED;
- previousMillis = currentMillis;
- }
- j = 1;
- break;
- }
- }
- void controlLights_Normally() {
- currentMillis = millis();
- if (i == 0) {
- // Traffic Light 1
- trafficLightControl(red1Pin, yellow1Pin, green1Pin, lightState1, previousMillis1, currentMillis, interval1);
- }
- else if (i == 1) {
- // Traffic Light 2
- trafficLightControl(red2Pin, yellow2Pin, green2Pin, lightState2, previousMillis2, currentMillis, interval2);
- }
- }
- void setup() {
- RemoteXY_Init ();
- Serial.begin(9600);
- setupInputsOutputs();
- turnAllLightsRED();
- }
- void loop() {
- RemoteXY_Handler ();
- if (RemoteXY.button_01 != 0) {
- /* button pressed */
- flagg = 1;// 1 = normal
- Serial.println("flagg = 1");
- }
- if (RemoteXY.button_02 != 0) {
- /* button pressed */
- flagg = 2;// 2 = Traffic Light 1 is Green
- Serial.println("flagg = 2");
- }
- if (RemoteXY.button_03 != 0) {
- /* button pressed */
- flagg = 3;// 3 = Traffic Light 2 is Green
- Serial.println("flagg = 3");
- }
- if (flagg == 1) {
- controlLights_Normally();
- }
- // 2 = Traffic Light 1 is Green
- else if (flagg == 2) {
- digitalWrite(red1Pin, LOW);
- digitalWrite(yellow1Pin, LOW);
- digitalWrite(green1Pin, HIGH);
- digitalWrite(red2Pin, HIGH);
- digitalWrite(yellow2Pin, LOW);
- digitalWrite(green2Pin, LOW);
- }
- // 3 = Traffic Light 2 is Green
- else if (flagg == 3) {
- digitalWrite(red1Pin, HIGH);
- digitalWrite(yellow1Pin, LOW);
- digitalWrite(green1Pin, LOW);
- digitalWrite(red2Pin, LOW);
- digitalWrite(yellow2Pin, LOW);
- digitalWrite(green2Pin, HIGH);
- }
- }//end of loop
Advertisement
Add Comment
Please, Sign In to add comment