Advertisement
Guest User

Nadajnik

a guest
Aug 15th, 2016
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.31 KB | None | 0 0
  1. #include <VirtualWire.h>
  2. #include <PCF8574.h>
  3. #include <Wire.h>
  4. #include <LiquidCrystal_I2C.h>
  5.  
  6. #define BACKLIGHT_PIN 3
  7. LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7);
  8. PCF8574 Expander;
  9.  
  10. int ActiveScene = 0;
  11.  
  12. void WriteLCD(int Scene){
  13. switch(Scene){
  14. case 0:
  15. lcd.clear();
  16. lcd.print("Wybierz kolor:");
  17. lcd.setCursor(0,1);
  18. lcd.print("OK - START");
  19. break;
  20. case 1:
  21. lcd.clear();
  22. lcd.print((char)126);
  23. lcd.print("Bialy");
  24. lcd.setCursor(0,1);
  25. lcd.print(" Czerwony");
  26. break;
  27. case 2:
  28. lcd.clear();
  29. lcd.print(" Bialy");
  30. lcd.setCursor(0,1);
  31. lcd.print((char)126);
  32. lcd.print("Czerwony");
  33. break;
  34. case 3:
  35. lcd.clear();
  36. lcd.print(" Czerwony");
  37. lcd.setCursor(0,1);
  38. lcd.print((char)126);
  39. lcd.print("Zielony");
  40. break;
  41. case 4:
  42. lcd.clear();
  43. lcd.print((char)126);
  44. lcd.print("Czerwony");
  45. lcd.setCursor(0,1);
  46. lcd.print(" Zielony");
  47. break;
  48. case 5:
  49. lcd.clear();
  50. lcd.print(" Zielony");
  51. lcd.setCursor(0,1);
  52. lcd.print((char)126);
  53. lcd.print("Niebieski");
  54. break;
  55. case 6:
  56. lcd.clear();
  57. lcd.print((char)126);
  58. lcd.print("Zielony");
  59. lcd.setCursor(0,1);
  60. lcd.print(" Niebieski");
  61. break;
  62. case 7:
  63. lcd.clear();
  64. lcd.print(" Niebieski");
  65. lcd.setCursor(0,1);
  66. lcd.print((char)126);
  67. lcd.print("Wlasny");
  68. break;
  69. case 8:
  70. lcd.clear();
  71. lcd.print((char)126);
  72. lcd.print("Niebieski");
  73. lcd.setCursor(0,1);
  74. lcd.print(" Wlasny");
  75. break;
  76. }
  77. }
  78.  
  79. int SelectScene(int State0, int State1, int State2){
  80. switch(ActiveScene){
  81. case 0:
  82. if(State0 == LOW)return 0;
  83. if(State1 == LOW)return 0;
  84. if(State2 == LOW)return 1;
  85. break;
  86. case 1:
  87. if(State0 == LOW)return 1;
  88. if(State1 == LOW)return 2;
  89. if(State2 == LOW)return 101;
  90. break;
  91. case 2:
  92. if(State0 == LOW)return 1;
  93. if(State1 == LOW)return 3;
  94. if(State2 == LOW)return 102;
  95. break;
  96. case 3:
  97. if(State0 == LOW)return 4;
  98. if(State1 == LOW)return 5;
  99. if(State2 == LOW)return 103;
  100. break;
  101. case 4:
  102. if(State0 == LOW)return 1;
  103. if(State1 == LOW)return 3;
  104. if(State2 == LOW)return 104;
  105. break;
  106. case 5:
  107. if(State0 == LOW)return 6;
  108. if(State1 == LOW)return 7;
  109. if(State2 == LOW)return 105;
  110. break;
  111. case 6:
  112. if(State0 == LOW)return 4;
  113. if(State1 == LOW)return 5;
  114. if(State2 == LOW)return 106;
  115. break;
  116. case 7:
  117. if(State0 == LOW)return 8;
  118. if(State1 == LOW)return 7;
  119. if(State2 == LOW)return 107;
  120. break;
  121. case 8:
  122. if(State0 == LOW)return 6;
  123. if(State1 == LOW)return 7;
  124. if(State2 == LOW)return 108;
  125. break;
  126. }
  127. }
  128.  
  129. void SendMessage(int msgA){
  130. const char *msg;
  131. vw_send((uint8_t *)msg, 1);
  132. vw_wait_tx();
  133. }
  134.  
  135. void setup()
  136. {
  137. Expander.begin(0x20);
  138. Expander.pinMode(0, INPUT_PULLUP);
  139. Expander.pinMode(1, INPUT_PULLUP);
  140. Expander.pinMode(2, INPUT_PULLUP);
  141. Expander.pinMode(3, INPUT_PULLUP);
  142. pinMode(A0, INPUT);
  143. lcd.begin (16,2);
  144. lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  145. lcd.setBacklight(HIGH);
  146. }
  147.  
  148. void loop()
  149. {
  150. int State0 = Expander.digitalRead(1);
  151. int State1 = Expander.digitalRead(3);
  152. int State2 = Expander.digitalRead(2);
  153.  
  154. ActiveScene = SelectScene(State0, State1, State2);
  155. if(ActiveScene > 50)SendMessage(ActiveScene - 100);
  156. else WriteLCD(ActiveScene);
  157. delay(200);
  158.  
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement