nikolas77

eclairages des batiments

Aug 4th, 2020 (edited)
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.17 KB | None | 0 0
  1. #include <Adafruit_GFX.h>
  2. #include <SPI.h>
  3. #include <Wire.h>
  4. #include <Adafruit_ILI9341.h>
  5. #include <Adafruit_STMPE610.h>
  6.  
  7. #define TS_MINX 150
  8. #define TS_MINY 130
  9. #define TS_MAXX 3800
  10. #define TS_MAXY 4000
  11.  
  12. #define STMPE_CS 8
  13. Adafruit_STMPE610 ts = Adafruit_STMPE610(STMPE_CS);
  14.  
  15. #define TFT_CS 10
  16. #define TFT_DC 9
  17. Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
  18. //*********************************************************************
  19. #define BrocheGare 22 //1)gare, gare routiere, quai
  20. boolean etatBoutonGare = false;
  21. boolean LastetatBoutonGare = true;
  22. //*********************************************************************
  23. #define BrocheLidl 24 //2)Lidl
  24. boolean etatBoutonLidl = false;
  25. boolean LastetatBoutonLidl = true;
  26. //*********************************************************************
  27. #define BrochePublic 26 //3)Public
  28. boolean etatBoutonPublic = false;
  29. boolean LastetatBoutonPublic = true;
  30. //*********************************************************************
  31. #define BrocheGarageLoco 28 //4)garage loco + buttoirs
  32. boolean etatBoutonGarageLoco = false;
  33. boolean LastetatBoutonGarageLoco = true;
  34. //*********************************************************************
  35. #define BrocheRestaurant 30 //5)restaurant
  36. boolean etatBoutonRestaurant = false;
  37. boolean LastetatBoutonRestaurant = true;
  38. //*********************************************************************
  39. #define BrocheVillage 32 //6)village
  40. boolean etatBoutonVillage = false;
  41. boolean LastetatBoutonVillage = true;
  42. //*********************************************************************
  43. #define BrocheStation 34 //7)station service
  44. boolean etatBoutonStation = false;
  45. boolean LastetatBoutonStation = true;
  46. //*********************************************************************
  47. #define BrocheEglise 36 //8)eglise + mairie
  48. boolean etatBoutonEglise = false;
  49. boolean LastetatBoutonEglise = true;
  50. //*********************************************************************
  51. #define BrocheRien1 38 //9)
  52. boolean etatBoutonRien1 = false;
  53. boolean LastetatBoutonRien1 = true;
  54. //*********************************************************************
  55. #define BrocheStationLavage 40 //10)Station Lavage
  56. boolean etatBoutonStationLavage = false;
  57. boolean LastetatBoutonStationLavage = true;
  58. //*********************************************************************
  59. #define BrocheRien2 42 //11)
  60. boolean etatBoutonRien2 = false;
  61. boolean LastetatBoutonRien2 = true;
  62. //*********************************************************************
  63. #define BrocheRien3 44 //12)
  64. boolean etatBoutonRien3 = false;
  65. boolean LastetatBoutonRien3 = true;
  66.  
  67. #define PressionMin 2
  68. #define PressionMax 1000
  69.  
  70. unsigned long tempoPression = 0;
  71.  
  72. void setup()
  73. {
  74. Serial.begin(9600);
  75.  
  76. pinMode(BrocheGare, OUTPUT);
  77. pinMode(BrocheLidl, OUTPUT);
  78. pinMode(BrochePublic, OUTPUT);
  79. pinMode(BrocheGarageLoco, OUTPUT);
  80. pinMode(BrocheRestaurant, OUTPUT);
  81. pinMode(BrocheVillage, OUTPUT);
  82. pinMode(BrocheStation, OUTPUT);
  83. pinMode(BrocheEglise, OUTPUT);
  84. pinMode(BrocheRien1, OUTPUT);
  85. pinMode(BrocheStationLavage, OUTPUT);
  86. pinMode(BrocheRien2, OUTPUT);
  87. pinMode(BrocheRien3, OUTPUT);
  88.  
  89. tft.begin();
  90. tft.setRotation(1);
  91. tft.fillScreen(ILI9341_BLACK);
  92.  
  93. tft.setTextColor(ILI9341_WHITE);
  94. tft.setTextSize(2);
  95. tft.setCursor(20, 7);
  96. tft.print("ECLAIRAGES DES BATIMENTS");
  97. tft.drawRoundRect(0, 0, 320, 240, 20, ILI9341_BLUE);
  98. tft.drawRoundRect(1, 1, 318, 238, 20, ILI9341_BLUE);
  99.  
  100. if (!ts.begin()) {
  101. while (1);
  102. }
  103. }
  104.  
  105. void loop(){
  106.  
  107. GestionTactile();
  108. GestionBouton();
  109. }
  110. //******************************
  111. //*** Fonction Gestion Bouton **
  112. //********************************************************************************
  113. void GestionBouton(){
  114.  
  115. if (LastetatBoutonGare != etatBoutonGare)
  116. {
  117. uint16_t coulBoutonGare = ILI9341_RED;
  118. if (etatBoutonGare) {coulBoutonGare = ILI9341_BLUE;}
  119.  
  120. tft.setTextColor(ILI9341_WHITE);
  121. tft.setTextSize(1);
  122. tft.fillRoundRect(5, 40, 90, 30, 12, coulBoutonGare);
  123. tft.drawRoundRect(3, 38, 94, 34, 12, coulBoutonGare);
  124. tft.setCursor(10, 45); tft.print(F("Gare, Quais "));
  125. tft.setCursor(10, 55); tft.print(F("Gare Routiere"));
  126. LastetatBoutonGare = etatBoutonGare;
  127. }
  128. //*******************************************************************************
  129. if (LastetatBoutonLidl != etatBoutonLidl)
  130. {
  131. uint16_t coulBoutonLidl = ILI9341_RED;
  132. if (etatBoutonLidl) {coulBoutonLidl = ILI9341_BLUE;}
  133.  
  134. tft.setTextColor(ILI9341_WHITE);
  135. tft.setTextSize(1);
  136. tft.fillRoundRect(115, 40, 90, 30, 12, coulBoutonLidl);
  137. tft.drawRoundRect(113, 38, 94, 34, 12, coulBoutonLidl);
  138. tft.setCursor(145, 50); tft.print(F("Lidl"));
  139. LastetatBoutonLidl = etatBoutonLidl;
  140. }
  141. //*******************************************************************************
  142. if (LastetatBoutonPublic != etatBoutonPublic)
  143. {
  144. uint16_t coulBoutonPublic= ILI9341_RED;
  145. if (etatBoutonPublic) {coulBoutonPublic = ILI9341_BLUE;}
  146.  
  147. tft.setTextColor(ILI9341_WHITE);
  148. tft.setTextSize(1);
  149. tft.fillRoundRect(225, 40, 90, 30, 12, coulBoutonPublic);
  150. tft.drawRoundRect(223, 38, 94, 34, 12, coulBoutonPublic);
  151. tft.setCursor(250, 50); tft.print(F("Publics"));
  152. LastetatBoutonPublic= etatBoutonPublic;
  153. }
  154. //*******************************************************************************
  155. if (LastetatBoutonGarageLoco != etatBoutonGarageLoco)
  156. {
  157. uint16_t coulBoutonGarageLoco= ILI9341_RED;
  158. if (etatBoutonGarageLoco) {coulBoutonGarageLoco = ILI9341_BLUE;}
  159.  
  160. tft.setTextColor(ILI9341_WHITE);
  161. tft.setTextSize(1);
  162. tft.fillRoundRect(5, 90, 90, 30, 12, coulBoutonGarageLoco);
  163. tft.drawRoundRect(3, 88, 94, 34, 12, coulBoutonGarageLoco);
  164. tft.setCursor(10, 95); tft.print(F("Garage locos,"));
  165. tft.setCursor(30, 105); tft.print(F("Buttoirs"));
  166. LastetatBoutonGarageLoco= etatBoutonGarageLoco;
  167. }
  168. //*******************************************************************************
  169. if (LastetatBoutonRestaurant != etatBoutonRestaurant)
  170. {
  171. uint16_t coulBoutonRestaurant= ILI9341_RED;
  172. if (etatBoutonRestaurant) {coulBoutonRestaurant = ILI9341_BLUE;}
  173.  
  174. tft.setTextColor(ILI9341_WHITE);
  175. tft.setTextSize(1);
  176. tft.fillRoundRect(115, 90, 90, 30, 12, coulBoutonRestaurant);
  177. tft.drawRoundRect(113, 88, 94, 34, 12, coulBoutonRestaurant);
  178. tft.setCursor(130, 100); tft.print(F("Restaurant"));
  179. LastetatBoutonRestaurant = etatBoutonRestaurant;
  180. }
  181. //********************************************************************************
  182. if (LastetatBoutonVillage != etatBoutonVillage)
  183. {
  184. uint16_t coulBoutonVillage= ILI9341_RED;
  185. if (etatBoutonVillage) {coulBoutonVillage = ILI9341_BLUE;}
  186.  
  187. tft.setTextColor(ILI9341_WHITE);
  188. tft.setTextSize(1);
  189. tft.fillRoundRect(225, 90, 90, 30, 12, coulBoutonVillage);
  190. tft.drawRoundRect(223, 88, 94, 34, 12, coulBoutonVillage);
  191. tft.setCursor(250, 100); tft.print(F("Village"));
  192. LastetatBoutonVillage = etatBoutonVillage;
  193. }
  194. //********************************************************************************
  195. if (LastetatBoutonStation != etatBoutonStation)
  196. {
  197. uint16_t coulBoutonStation= ILI9341_RED;
  198. if (etatBoutonStation) {coulBoutonStation = ILI9341_BLUE;}
  199.  
  200. tft.setTextColor(ILI9341_WHITE);
  201. tft.setTextSize(1);
  202. tft.fillRoundRect(5, 140, 90, 30, 12, coulBoutonStation);
  203. tft.drawRoundRect(3, 138, 94, 34, 12, coulBoutonStation);
  204. tft.setCursor(6, 150); tft.print(F("Station Service"));
  205. LastetatBoutonStation = etatBoutonStation;
  206. }
  207. //********************************************************************************
  208. if (LastetatBoutonEglise != etatBoutonEglise)
  209. {
  210. uint16_t coulBoutonEglise= ILI9341_RED;
  211. if (etatBoutonEglise) {coulBoutonEglise = ILI9341_BLUE;}
  212.  
  213. tft.setTextColor(ILI9341_WHITE);
  214. tft.setTextSize(1);
  215. tft.fillRoundRect(115, 140, 90, 30, 12, coulBoutonEglise);
  216. tft.drawRoundRect(113, 138, 94, 34, 12, coulBoutonEglise);
  217. tft.setCursor(120, 150); tft.print(F("Eglise, Mairie"));
  218. LastetatBoutonEglise = etatBoutonEglise;
  219. }
  220. //*******************************************************************************
  221. if (LastetatBoutonRien1 != etatBoutonRien1)
  222. {
  223. uint16_t coulBoutonRien1= ILI9341_RED;
  224. if (etatBoutonRien1) {coulBoutonRien1 = ILI9341_BLUE;}
  225.  
  226. tft.setTextColor(ILI9341_WHITE);
  227. tft.setTextSize(1);
  228. tft.fillRoundRect(225, 140, 90, 30, 12, coulBoutonRien1);
  229. tft.drawRoundRect(223, 138, 94, 34, 12, coulBoutonRien1);
  230. tft.setCursor(250, 150); tft.print(F(""));
  231. LastetatBoutonRien1 = etatBoutonRien1;
  232. }
  233.  
  234. //********************************************************************************
  235. if (LastetatBoutonStationLavage != etatBoutonStationLavage)
  236. {
  237. uint16_t coulBoutonStationLavage= ILI9341_RED;
  238. if (etatBoutonStationLavage) {coulBoutonStationLavage = ILI9341_BLUE;}
  239.  
  240. tft.setTextColor(ILI9341_WHITE);
  241. tft.setTextSize(1);
  242. tft.fillRoundRect(5, 190, 90, 30, 12, coulBoutonStationLavage);
  243. tft.drawRoundRect(3, 188, 94, 34, 12, coulBoutonStationLavage);
  244. tft.setCursor(10, 195); tft.print(F("Station Lavage"));
  245. tft.setCursor(10, 205); tft.print(F("locos, Wagons"));
  246. LastetatBoutonStationLavage = etatBoutonStationLavage;
  247. }
  248. //********************************************************************************
  249. if (LastetatBoutonRien2 != etatBoutonRien2)
  250. {
  251. uint16_t coulBoutonRien2 = ILI9341_RED;
  252. if (etatBoutonRien2 ) {coulBoutonRien2 = ILI9341_BLUE;}
  253.  
  254. tft.setTextColor(ILI9341_WHITE);
  255. tft.setTextSize(1);
  256. tft.fillRoundRect(115, 190, 90, 30, 12, coulBoutonRien2);
  257. tft.drawRoundRect(113, 188, 94, 34, 12, coulBoutonRien2);
  258. tft.setCursor(140, 200); tft.print(F(""));
  259. LastetatBoutonRien2 = etatBoutonRien2;
  260. }
  261. //*********************************************************************************
  262. if (LastetatBoutonRien3 != etatBoutonRien3)
  263. {
  264. uint16_t coulBoutonRien3= ILI9341_RED;
  265. if (etatBoutonRien3) {coulBoutonRien3 = ILI9341_BLUE;}
  266.  
  267. tft.setTextColor(ILI9341_WHITE);
  268. tft.setTextSize(1);
  269. tft.fillRoundRect(225, 190, 90, 30, 12, coulBoutonRien3);
  270. tft.drawRoundRect(223, 188, 94, 34, 12, coulBoutonRien3);
  271. tft.setCursor(250, 200); tft.print(F(""));
  272. LastetatBoutonRien3 = etatBoutonRien3;
  273. }
  274. }
  275. //*********************************************************************************
  276. //*** Fonction Gestion Tactile de l'écran TFT *************************************
  277. //*********************************************************************************
  278. void GestionTactile (){
  279.  
  280. if (ts.bufferEmpty()) {
  281. return;
  282. }
  283.  
  284. TS_Point p = ts.getPoint();
  285.  
  286. p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
  287. p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
  288.  
  289. Serial.print(p.x);
  290. Serial.print(" , ");
  291. Serial.println(p.y);
  292. //**********************************************************************************
  293. if (millis() - tempoPression >= 1000ul && tempoPression != 0 || tempoPression == 0)
  294. {
  295. if (p.x > 230 && p.x < 270 && p.y > 20 && p.y < 70) //ecl gare , gare routiere , quais
  296. {
  297. etatBoutonGare = !etatBoutonGare;
  298. digitalWrite(BrocheGare, etatBoutonGare);
  299. }
  300. //**********************************************************************************
  301. if (p.x > 230 && p.x < 270 && p.y > 90 && p.y < 150) //ecl Lidl
  302. {
  303. etatBoutonLidl = !etatBoutonLidl;
  304. digitalWrite(BrocheLidl, etatBoutonLidl);
  305. }
  306. //**********************************************************************************
  307. if (p.x > 230 && p.x < 270 && p.y > 180 && p.y < 220) //ecl Public
  308. {
  309. etatBoutonPublic = !etatBoutonPublic;
  310. digitalWrite(BrochePublic, etatBoutonPublic);
  311. }
  312. //**********************************************************************************
  313. if (p.x > 180 && p.x < 220 && p.y > 30 && p.y < 70) //ecl garage loco + buttoirs
  314. {
  315. etatBoutonGarageLoco = !etatBoutonGarageLoco;
  316. digitalWrite(BrocheGarageLoco, etatBoutonGarageLoco);
  317. }
  318. //**********************************************************************************
  319. if (p.x > 180 && p.x < 220 && p.y > 90 && p.y < 150) //ecl restaurant
  320. {
  321. etatBoutonRestaurant = !etatBoutonRestaurant;
  322. digitalWrite(BrocheRestaurant, etatBoutonRestaurant);
  323. }
  324. //**********************************************************************************
  325. if (p.x > 180 && p.x < 220 && p.y > 180 && p.y < 220) //ecl Village
  326. {
  327. etatBoutonVillage = !etatBoutonVillage;
  328. digitalWrite(BrocheVillage, etatBoutonVillage);
  329. }
  330. //**********************************************************************************
  331. if (p.x > 100 && p.x < 140 && p.y > 30 && p.y < 70) //ecl Station service
  332. {
  333. etatBoutonStation = !etatBoutonStation;
  334. digitalWrite(BrocheStation, etatBoutonStation);
  335. }
  336. //**********************************************************************************
  337. if (p.x > 100 && p.x < 140 && p.y > 90 && p.y < 150) //ecl église + mairie
  338. {
  339. etatBoutonEglise = !etatBoutonEglise;
  340. digitalWrite(BrocheEglise, etatBoutonEglise);
  341. }
  342. //**********************************************************************************
  343. if (p.x > 100 && p.x < 140 && p.y > 180 && p.y < 220) //non connecter 1
  344. {
  345. etatBoutonRien1 = !etatBoutonRien1;
  346. digitalWrite(BrocheRien1, etatBoutonRien1);
  347. }
  348. //**********************************************************************************
  349. if (p.x > 20 && p.x < 60 && p.y > 30 && p.y < 70) //ecl Station Lavage
  350. {
  351. etatBoutonStationLavage = !etatBoutonStationLavage;
  352. digitalWrite(BrocheStationLavage, etatBoutonStationLavage);
  353. }
  354. //**********************************************************************************
  355. if (p.x > 20 && p.x < 60 && p.y > 90 && p.y < 150) //non connecter 2
  356. {
  357. etatBoutonRien2 = !etatBoutonRien2 ;
  358. digitalWrite(BrocheRien2 , etatBoutonRien2 );
  359. }
  360. //**********************************************************************************
  361. if (p.x > 20 && p.x < 60 && p.y > 180 && p.y < 220) //non connecter 3
  362. {
  363. etatBoutonRien3 = !etatBoutonRien3;
  364. digitalWrite(BrocheRien3, etatBoutonRien3);
  365. }
  366. tempoPression = millis();
  367. }
  368. }
Add Comment
Please, Sign In to add comment