Advertisement
Guest User

Untitled

a guest
May 24th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.77 KB | None | 0 0
  1. #include <SPI.h>
  2. #include <Adafruit_GFX.h>
  3. #include <Adafruit_PCD8544.h>
  4.  
  5. #define STROBE_OFF 0
  6. #define STROBE_MODE_1 1
  7. #define STROBE_MODE_2 2
  8. #define STROBE_MODE_3 3
  9.  
  10. char * strobeLabels[] = {"", " BRAKE", " REAR", " SOLID"};
  11. char * fogLabels[] = {"", " ON", " AUTO"};
  12.  
  13. #define FOG_OFF 0
  14. #define FOG_ON 1
  15. #define FOG_AUTO 2
  16.  
  17. Adafruit_PCD8544 display = Adafruit_PCD8544(9, 10, 11, 12, 13);
  18.  
  19. static const unsigned char PROGMEM logo38X29_off_bmp[] =
  20. {
  21. 0x0,0x0,0x0,0x0,0x0,
  22. 0x0,0x0,0x0,0x0,0x0,
  23. 0x0,0x0,0x0,0x0,0x0,
  24. 0x0,0x0,0x0,0x0,0x0,
  25. 0x0,0x0,0x0,0x0,0x0,
  26. 0x0,0x0,0x0,0x0,0x0,
  27. 0x1,0xf0,0x3f,0x9f,0xc0,
  28. 0x3,0xfc,0x3f,0x9f,0xc0,
  29. 0x7,0xfe,0x3f,0x9f,0xc0,
  30. 0x7,0x9e,0x3f,0x9f,0xc0,
  31. 0x7,0x9e,0x3c,0x1e,0x0,
  32. 0x7,0x9e,0x3c,0x1e,0x0,
  33. 0x7,0x9e,0x3c,0x1e,0x0,
  34. 0x7,0x9e,0x3f,0x9f,0xc0,
  35. 0x7,0x9e,0x3f,0x9f,0xc0,
  36. 0x7,0x9e,0x3f,0x9f,0xc0,
  37. 0x7,0x9e,0x3f,0x9f,0xc0,
  38. 0x7,0x9e,0x3c,0x1e,0x0,
  39. 0x7,0x9e,0x3c,0x1e,0x0,
  40. 0x7,0x9e,0x3c,0x1e,0x0,
  41. 0x7,0x9e,0x3c,0x1e,0x0,
  42. 0x7,0xfe,0x3c,0x1e,0x0,
  43. 0x3,0xfc,0x3c,0x1e,0x0,
  44. 0x0,0xf8,0x3c,0x1e,0x0,
  45. 0x0,0x0,0x0,0x0,0x0,
  46. 0x0,0x0,0x0,0x0,0x0,
  47. 0x0,0x0,0x0,0x0,0x0,
  48. 0x0,0x0,0x0,0x0,0x0,
  49. 0x0,0x0,0x0,0x0,0x0
  50. };
  51.  
  52. static const unsigned char PROGMEM logo38X29_fog_bmp[] =
  53. {
  54. 0x0,0x0,0x0,0x0,0x0,
  55. 0x0,0x0,0x0,0x0,0x0,
  56. 0x0,0x0,0x0,0x0,0x0,
  57. 0x0,0x0,0x0,0x8,0x0,
  58. 0x0,0x7,0x80,0xc,0x0,
  59. 0x0,0x1f,0xe0,0xe,0x0,
  60. 0x0,0xfc,0xe0,0x6,0x0,
  61. 0x1,0xf0,0x70,0x3,0x0,
  62. 0x3,0xc0,0x33,0xff,0xc0,
  63. 0x7,0x0,0x33,0xff,0xc0,
  64. 0xe,0x0,0x30,0x3,0x0,
  65. 0x1c,0x0,0x30,0x6,0x0,
  66. 0x1c,0x0,0x30,0xe,0x0,
  67. 0x18,0x0,0x30,0xc,0x0,
  68. 0x18,0x0,0x33,0xff,0xc0,
  69. 0x18,0x0,0x33,0xff,0xc0,
  70. 0x18,0x0,0x30,0x18,0x0,
  71. 0x1c,0x0,0x30,0x18,0x0,
  72. 0xc,0x0,0x30,0x38,0x0,
  73. 0xe,0x0,0x30,0x30,0x0,
  74. 0x7,0x80,0x33,0xff,0xc0,
  75. 0x3,0xc0,0x33,0xff,0xc0,
  76. 0x1,0xf0,0x70,0x30,0x0,
  77. 0x0,0x7c,0xe0,0x18,0x0,
  78. 0x0,0x3f,0xe0,0x1c,0x0,
  79. 0x0,0x7,0x80,0xc,0x0,
  80. 0x0,0x0,0x0,0x4,0x0,
  81. 0x0,0x0,0x0,0x0,0x0,
  82. 0x0,0x0,0x0,0x0,0x0
  83. };
  84.  
  85. static const unsigned char PROGMEM logo38X29_fog2_bmp[] =
  86. {
  87. 0x0,0x0,0x0,0x0,0x0,
  88. 0x0,0x0,0x0,0x0,0x0,
  89. 0x0,0x0,0x0,0x0,0x0,
  90. 0x0,0x0,0x0,0x8,0x0,
  91. 0x0,0x7,0x80,0xc,0x0,
  92. 0x0,0x1f,0xe0,0xe,0x0,
  93. 0x0,0xff,0xe0,0x6,0x0,
  94. 0x1,0xff,0xf0,0x3,0x0,
  95. 0x3,0xff,0xf3,0xff,0xc0,
  96. 0x7,0xff,0xf3,0xff,0xc0,
  97. 0xf,0xff,0xf0,0x3,0x0,
  98. 0x1f,0xff,0xf0,0x6,0x0,
  99. 0x1f,0xff,0xf0,0xe,0x0,
  100. 0x1f,0xff,0xf0,0xc,0x0,
  101. 0x1f,0xff,0xf3,0xff,0xc0,
  102. 0x1f,0xff,0xf3,0xff,0xc0,
  103. 0x1f,0xff,0xf0,0x18,0x0,
  104. 0x1f,0xff,0xf0,0x18,0x0,
  105. 0xf,0xff,0xf0,0x38,0x0,
  106. 0xf,0xff,0xf0,0x30,0x0,
  107. 0x7,0xff,0xf3,0xff,0xc0,
  108. 0x3,0xff,0xf3,0xff,0xc0,
  109. 0x1,0xff,0xf0,0x30,0x0,
  110. 0x0,0x7f,0xe0,0x18,0x0,
  111. 0x0,0x3f,0xe0,0x1c,0x0,
  112. 0x0,0x7,0x80,0xc,0x0,
  113. 0x0,0x0,0x0,0x4,0x0,
  114. 0x0,0x0,0x0,0x0,0x0,
  115. 0x0,0x0,0x0,0x0,0x0
  116. };
  117.  
  118. static const unsigned char PROGMEM logo38X29_1_bmp[] =
  119. {
  120. 0x0,0x0,0x0,0x0,0x0,
  121. 0x0,0x0,0x0,0x0,0x0,
  122. 0x0,0x0,0x0,0x0,0x0,
  123. 0x0,0x0,0x0,0x0,0x0,
  124. 0x0,0x0,0x0,0x0,0x0,
  125. 0x0,0x0,0x0,0x0,0x0,
  126. 0x0,0x0,0x18,0x0,0x0,
  127. 0x0,0x0,0x38,0x0,0x0,
  128. 0x0,0x0,0xf8,0x0,0x0,
  129. 0x0,0x3,0xf8,0x0,0x0,
  130. 0x0,0x3,0xf8,0x0,0x0,
  131. 0x0,0x0,0x78,0x0,0x0,
  132. 0x0,0x0,0x78,0x0,0x0,
  133. 0x0,0x0,0x78,0x0,0x0,
  134. 0x0,0x0,0x78,0x0,0x0,
  135. 0x0,0x0,0x78,0x0,0x0,
  136. 0x0,0x0,0x78,0x0,0x0,
  137. 0x0,0x0,0x78,0x0,0x0,
  138. 0x0,0x0,0x78,0x0,0x0,
  139. 0x0,0x0,0x78,0x0,0x0,
  140. 0x0,0x0,0x78,0x0,0x0,
  141. 0x0,0x0,0x78,0x0,0x0,
  142. 0x0,0x0,0x78,0x0,0x0,
  143. 0x0,0x0,0x78,0x0,0x0,
  144. 0x0,0x0,0x0,0x0,0x0,
  145. 0x0,0x0,0x0,0x0,0x0,
  146. 0x0,0x0,0x0,0x0,0x0,
  147. 0x0,0x0,0x0,0x0,0x0,
  148. 0x0,0x0,0x0,0x0,0x0
  149. };
  150.  
  151. static const unsigned char PROGMEM logo38X29_2_bmp[] =
  152. {
  153. 0x0,0x0,0x0,0x0,0x0,
  154. 0x0,0x0,0x0,0x0,0x0,
  155. 0x0,0x0,0x0,0x0,0x0,
  156. 0x0,0x0,0x0,0x0,0x0,
  157. 0x0,0x0,0x0,0x0,0x0,
  158. 0x0,0x0,0x0,0x0,0x0,
  159. 0x0,0x0,0x7c,0x0,0x0,
  160. 0x0,0x0,0xfe,0x0,0x0,
  161. 0x0,0x1,0xff,0x0,0x0,
  162. 0x0,0x1,0xcf,0x0,0x0,
  163. 0x0,0x1,0xcf,0x0,0x0,
  164. 0x0,0x1,0xcf,0x0,0x0,
  165. 0x0,0x1,0xcf,0x0,0x0,
  166. 0x0,0x0,0x1e,0x0,0x0,
  167. 0x0,0x0,0x1e,0x0,0x0,
  168. 0x0,0x0,0x3e,0x0,0x0,
  169. 0x0,0x0,0x3c,0x0,0x0,
  170. 0x0,0x0,0x78,0x0,0x0,
  171. 0x0,0x0,0x78,0x0,0x0,
  172. 0x0,0x0,0xf0,0x0,0x0,
  173. 0x0,0x0,0xf0,0x0,0x0,
  174. 0x0,0x1,0xff,0x0,0x0,
  175. 0x0,0x1,0xff,0x0,0x0,
  176. 0x0,0x1,0xff,0x0,0x0,
  177. 0x0,0x0,0x0,0x0,0x0,
  178. 0x0,0x0,0x0,0x0,0x0,
  179. 0x0,0x0,0x0,0x0,0x0,
  180. 0x0,0x0,0x0,0x0,0x0,
  181. 0x0,0x0,0x0,0x0,0x0
  182. };
  183.  
  184. static const unsigned char PROGMEM logo38X29_3_bmp[] =
  185. {
  186. 0x0,0x0,0x0,0x0,0x0,
  187. 0x0,0x0,0x0,0x0,0x0,
  188. 0x0,0x0,0x0,0x0,0x0,
  189. 0x0,0x0,0x0,0x0,0x0,
  190. 0x0,0x0,0x0,0x0,0x0,
  191. 0x0,0x0,0x0,0x0,0x0,
  192. 0x0,0x0,0xfc,0x0,0x0,
  193. 0x0,0x1,0xfe,0x0,0x0,
  194. 0x0,0x1,0xff,0x0,0x0,
  195. 0x0,0x1,0xef,0x0,0x0,
  196. 0x0,0x1,0xef,0x0,0x0,
  197. 0x0,0x0,0xf,0x0,0x0,
  198. 0x0,0x0,0x3f,0x0,0x0,
  199. 0x0,0x0,0x3c,0x0,0x0,
  200. 0x0,0x0,0x3f,0x0,0x0,
  201. 0x0,0x0,0xf,0x0,0x0,
  202. 0x0,0x1,0xef,0x0,0x0,
  203. 0x0,0x1,0xef,0x0,0x0,
  204. 0x0,0x1,0xef,0x0,0x0,
  205. 0x0,0x1,0xef,0x0,0x0,
  206. 0x0,0x1,0xef,0x0,0x0,
  207. 0x0,0x1,0xff,0x0,0x0,
  208. 0x0,0x0,0xfe,0x0,0x0,
  209. 0x0,0x0,0x7c,0x0,0x0,
  210. 0x0,0x0,0x0,0x0,0x0,
  211. 0x0,0x0,0x0,0x0,0x0,
  212. 0x0,0x0,0x0,0x0,0x0,
  213. 0x0,0x0,0x0,0x0,0x0,
  214. 0x0,0x0,0x0,0x0,0x0
  215. };
  216.  
  217. void setup() {
  218. Serial.begin(9600);
  219.  
  220. display.begin();
  221. display.setContrast(60);
  222. display.display(); // show splashscreen
  223.  
  224.  
  225. delay(2000);
  226. display.clearDisplay(); // clears the screen and buffer
  227. }
  228.  
  229. // Distance bar
  230.  
  231. void cleanDistanceBar()
  232. {
  233. display.fillRect(0, 0, display.width(), display.height()/5, 0);
  234. }
  235. void drawDistanceBar(int size)
  236. {
  237. cleanDistanceBar();
  238. display.fillRect(0, 0, display.width() * size / 100, display.height()/5, 1);
  239. display.display();
  240. }
  241.  
  242. // Fog zone
  243.  
  244. void cleanFogIcon()
  245. {
  246. display.fillRect(0, display.height()/5, (display.width() / 2) - 1,
  247. (display.height() * 7 / 10) - 2, 0);
  248. display.display();
  249. }
  250.  
  251. void drawFogIcon(int mode)
  252. {
  253. cleanFogIcon();
  254.  
  255. if (mode == FOG_OFF)
  256. {
  257. display.drawBitmap(0, display.height()/5, logo38X29_off_bmp, 38, 29, 1);
  258. }
  259. else if (mode == FOG_ON)
  260. {
  261. display.drawBitmap(0, display.height()/5, logo38X29_fog_bmp, 38, 29, 1);
  262. }
  263. else if (mode == FOG_AUTO)
  264. {
  265. display.drawBitmap(0, display.height()/5, logo38X29_fog2_bmp, 38, 29, 1);
  266. }
  267. display.display();
  268. }
  269.  
  270. // Strobe zone
  271.  
  272. void cleanStrobeIcon()
  273. {
  274. display.fillRect((display.width()/2) + 1, display.height()/5, (display.width()/2) - 1,
  275. (display.height() * 7 / 10) - 2, 0);
  276. display.display();
  277. }
  278.  
  279. void drawStrobeIcon(int mode)
  280. {
  281. cleanStrobeIcon();
  282. if (mode == STROBE_OFF)
  283. {
  284. display.drawBitmap((display.width()/2) + 1, display.height()/5, logo38X29_off_bmp, 38, 29, 1);
  285. }
  286. else if (mode == STROBE_MODE_1)
  287. {
  288. display.drawBitmap((display.width()/2) + 1, display.height()/5, logo38X29_1_bmp, 38, 29, 1);
  289. }
  290. else if (mode == STROBE_MODE_2)
  291. {
  292. display.drawBitmap((display.width()/2) + 1, display.height()/5, logo38X29_2_bmp, 38, 29, 1);
  293. }
  294. else if (mode == STROBE_MODE_3)
  295. {
  296. display.drawBitmap((display.width()/2) + 1, display.height()/5, logo38X29_3_bmp, 38, 29, 1);
  297. }
  298.  
  299. display.display();
  300. }
  301.  
  302. // Divisor
  303.  
  304. void drawIconDivisor()
  305. {
  306. display.fillRect((display.width() / 2) - 1, (display.height() / 5) + 1, 2,
  307. (display.height() * 7 / 10) - 3, 1);
  308. display.display();
  309. }
  310.  
  311. // Write fog label
  312.  
  313. void writeFogLabel(char * label)
  314. {
  315. clearFogLabel();
  316. display.setCursor(0, (display.height() * 8 / 10) + 3);
  317. display.print(label);
  318. display.display();
  319. }
  320.  
  321. void clearFogLabel()
  322. {
  323. display.fillRect(0, (display.height() * 8 / 10) + 3, display.width() / 2, 7, 0);
  324. display.display();
  325. }
  326.  
  327. // Write strobe label
  328.  
  329. void writeStrobeLabel(char * label)
  330. {
  331. clearStrobeLabel();
  332. display.setCursor(display.width() / 2, (display.height() * 8 / 10) + 3);
  333. display.print(label);
  334. display.display();
  335. }
  336.  
  337. void clearStrobeLabel()
  338. {
  339. display.fillRect(display.width() / 2, (display.height() * 8 / 10) + 3,
  340. display.width() / 2, 7, 0);
  341. display.display();
  342. }
  343.  
  344. void updateLCDStrobe(int mode)
  345. {
  346. drawStrobeIcon(mode);
  347. writeStrobeLabel(strobeLabels[mode]);
  348. }
  349.  
  350. void updateLCDFog(int mode)
  351. {
  352. drawFogIcon(mode);
  353. writeFogLabel(fogLabels[mode]);
  354. }
  355.  
  356. void graphicsTest1(){
  357. int i = 0;
  358.  
  359. drawIconDivisor();
  360.  
  361. for (i = 0; i < 101; i++)
  362. {
  363. drawDistanceBar(i);
  364. }
  365.  
  366. for (i = 0; i < 4; i++)
  367. {
  368. updateLCDStrobe(i);
  369. delay(1000);
  370. }
  371.  
  372. for (i = 0; i < 3; i++)
  373. {
  374. updateLCDFog(i);
  375. delay(1000);
  376. }
  377. }
  378.  
  379. void loop() {
  380. graphicsTest1();
  381. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement