Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <VirtualWire.h>
- #include <PCF8574.h>
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- #define BACKLIGHT_PIN 3
- LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7);
- PCF8574 Expander;
- int ActiveScene = 0;
- void WriteLCD(int Scene){
- switch(Scene){
- case 0:
- lcd.clear();
- lcd.print("Wybierz kolor:");
- lcd.setCursor(0,1);
- lcd.print("OK - START");
- break;
- case 1:
- lcd.clear();
- lcd.print((char)126);
- lcd.print("Bialy");
- lcd.setCursor(0,1);
- lcd.print(" Czerwony");
- break;
- case 2:
- lcd.clear();
- lcd.print(" Bialy");
- lcd.setCursor(0,1);
- lcd.print((char)126);
- lcd.print("Czerwony");
- break;
- case 3:
- lcd.clear();
- lcd.print(" Czerwony");
- lcd.setCursor(0,1);
- lcd.print((char)126);
- lcd.print("Zielony");
- break;
- case 4:
- lcd.clear();
- lcd.print((char)126);
- lcd.print("Czerwony");
- lcd.setCursor(0,1);
- lcd.print(" Zielony");
- break;
- case 5:
- lcd.clear();
- lcd.print(" Zielony");
- lcd.setCursor(0,1);
- lcd.print((char)126);
- lcd.print("Niebieski");
- break;
- case 6:
- lcd.clear();
- lcd.print((char)126);
- lcd.print("Zielony");
- lcd.setCursor(0,1);
- lcd.print(" Niebieski");
- break;
- case 7:
- lcd.clear();
- lcd.print(" Niebieski");
- lcd.setCursor(0,1);
- lcd.print((char)126);
- lcd.print("Wlasny");
- break;
- case 8:
- lcd.clear();
- lcd.print((char)126);
- lcd.print("Niebieski");
- lcd.setCursor(0,1);
- lcd.print(" Wlasny");
- break;
- }
- }
- int SelectScene(int State0, int State1, int State2){
- switch(ActiveScene){
- case 0:
- if(State0 == LOW)return 0;
- if(State1 == LOW)return 0;
- if(State2 == LOW)return 1;
- break;
- case 1:
- if(State0 == LOW)return 1;
- if(State1 == LOW)return 2;
- if(State2 == LOW)return 101;
- break;
- case 2:
- if(State0 == LOW)return 1;
- if(State1 == LOW)return 3;
- if(State2 == LOW)return 102;
- break;
- case 3:
- if(State0 == LOW)return 4;
- if(State1 == LOW)return 5;
- if(State2 == LOW)return 103;
- break;
- case 4:
- if(State0 == LOW)return 1;
- if(State1 == LOW)return 3;
- if(State2 == LOW)return 104;
- break;
- case 5:
- if(State0 == LOW)return 6;
- if(State1 == LOW)return 7;
- if(State2 == LOW)return 105;
- break;
- case 6:
- if(State0 == LOW)return 4;
- if(State1 == LOW)return 5;
- if(State2 == LOW)return 106;
- break;
- case 7:
- if(State0 == LOW)return 8;
- if(State1 == LOW)return 7;
- if(State2 == LOW)return 107;
- break;
- case 8:
- if(State0 == LOW)return 6;
- if(State1 == LOW)return 7;
- if(State2 == LOW)return 108;
- break;
- }
- }
- void SendMessage(int msgA){
- const char *msg;
- vw_send((uint8_t *)msg, 1);
- vw_wait_tx();
- }
- void setup()
- {
- Expander.begin(0x20);
- Expander.pinMode(0, INPUT_PULLUP);
- Expander.pinMode(1, INPUT_PULLUP);
- Expander.pinMode(2, INPUT_PULLUP);
- Expander.pinMode(3, INPUT_PULLUP);
- pinMode(A0, INPUT);
- lcd.begin (16,2);
- lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
- lcd.setBacklight(HIGH);
- }
- void loop()
- {
- int State0 = Expander.digitalRead(1);
- int State1 = Expander.digitalRead(3);
- int State2 = Expander.digitalRead(2);
- ActiveScene = SelectScene(State0, State1, State2);
- if(ActiveScene > 50)SendMessage(ActiveScene - 100);
- else WriteLCD(ActiveScene);
- delay(200);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement