Advertisement
Ollivier

Affichage défilant avec saisie clavier par port série

Apr 14th, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.51 KB | None | 0 0
  1. // -----------------------------------------------------------------------------------------------------
  2. // Affichage et de défilement d'un texte | Afficheur à LED 4 Digit Alphanumérique Octopus EF04058
  3. // avec saisie clavier transmise par port serie
  4. // http://www.elecfreaks.com/wiki/index.php?title=Octopus_Alphanumeric_LED_Brick
  5. // https://learn.adafruit.com/adafruit-led-backpack/0-54-alphanumeric
  6. // =====================================================================================================
  7.  
  8.  
  9. // =====================================================================================================
  10. // Branchements I2C/Wire
  11. // =====================================================================================================
  12. // GRD => Grd
  13. // VCC => 5 V
  14. // SDA => SDA / A4
  15. // SCL => SCL / A5
  16. // =====================================================================================================
  17.  
  18. // =====================================================================================================
  19. // Disposition des segments
  20. // =====================================================================================================
  21. // ---- A ----
  22. // | \ | / |
  23. // F H J K B
  24. // | \ | / |
  25. // |-G1- | -G2-|
  26. // | / | \ |
  27. // E L M N C
  28. // | / | \ |
  29. // ---- D ---- (DP)
  30. //
  31. // ... ou dans mon cas :
  32. //
  33. // ---- A ----
  34. // | \ | / |
  35. // F H J K B
  36. // | \ | / |
  37. // |-G1- | -G2-|
  38. // | / | \ |
  39. // E (N) M (L) C
  40. // | / | \ |
  41. // ---- D ---- (DP)
  42. // =====================================================================================================
  43.  
  44.  
  45. // Chargement des librairies nécessaires ---------------------------------------------------------------
  46.  
  47. #include <Wire.h> // Librairie de cablage simplifié (??)
  48. #include "Adafruit_LEDBackpack.h" // Librairie d'affichage sur ecran LCD
  49. #include "Adafruit_GFX.h" // Librairie d'affichage graphique
  50.  
  51. // Déclaration de l'objet alpha4 -----------------------------------------------------------------------
  52.  
  53. Adafruit_AlphaNum4 alpha4 = Adafruit_AlphaNum4();
  54.  
  55. // Déclaration de la variable contenant la phrase à afficher -------------------------------------------
  56. // ATTENTION pas d'accent, pas de €, ni de ! désolé ----------------------------------------------------
  57.  
  58. String texteTotal = "Ouvrez la console serie et saisissez le texte a afficher";
  59.  
  60. // Déclaration de la variable contenant la séquence à afficher -----------------------------------------
  61. // initialement "zoll" même ça ne sert pas -------------------------------------------------------------
  62.  
  63. String texteBrut = "zoll";
  64.  
  65. // Détermination de l'ordre des blocs d'affichage. (Parce que mon afficheur est mal monté, je pense, ------
  66. // M et K sont inversés) et les deux modules de d'affichages eux-même le sont -----------------------------
  67.  
  68. int CL[4] = {2, 3, 0, 1};
  69.  
  70. // Remarque : J'aurais pu corriger le fichier Adafruit_LEDBackoack.cpp et utiliser la fonction ------------
  71. // alpha4.writeDigitAscii (). -----------------------------------------------------------------------------
  72.  
  73. // Tableau qui contient l'alphabet ------------------------------------------------------------------------
  74.  
  75. char alphaB[84] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890()<>'?.@%$&/+-=_:;,*°";
  76.  
  77. // Tableau qui contient l'alphabet en 0b00 auquel correspond le tableau de l'alphabet ---------------------
  78.  
  79. const unsigned long alphaB_0b00 [84] = {
  80. 0b0001000001011000, // a
  81. 0b0000100001111000, // b
  82. 0b0000000011011000, // c
  83. 0b0000000011011110, // d
  84. 0b0010000001011000, // e
  85. 0b0000000001110001, // f
  86. 0b0000000110001111, // g
  87. 0b0000100001110000, // h
  88. 0b0001000000000000, // i
  89. 0b0000000000001110, // j
  90. 0b0001111000000000, // k
  91. 0b0001001000000000, // l
  92. 0b0001000011010100, // m
  93. 0b0001000001010000, // n
  94. 0b0000000011011100, // o
  95. 0b0000000011110011, // p
  96. 0b0000000110000111, // q
  97. 0b0000000001010000, // r
  98. 0b0000100010001000, // s
  99. 0b0000000001111000, // t
  100. 0b0000000000011100, // u
  101. 0b0010000000010000, // v
  102. 0b0010100000010100, // w
  103. 0b0010100011000000, // x
  104. 0b0010001001100000, // y
  105. 0b0010000001001000, // z
  106. 0b0000000011110111, // A
  107. 0b0001001010001111, // B
  108. 0b0000000000111001, // C
  109. 0b0001001000001111, // D
  110. 0b0000000011111001, // E
  111. 0b0000000011110001, // F
  112. 0b0000000010111101, // G
  113. 0b0000000011110110, // H
  114. 0b0001001000000000, // I
  115. 0b0000000000011110, // J
  116. 0b0000110001110000, // K
  117. 0b0000000000111000, // L
  118. 0b0000010100110110, // M
  119. 0b0000100100110110, // N
  120. 0b0000000000111111, // O
  121. 0b0000000011110011, // P
  122. 0b0000100000111111, // Q
  123. 0b0000100011110011, // R
  124. 0b0000000011101101, // S
  125. 0b0001001000000001, // T
  126. 0b0000000000111110, // U
  127. 0b0010010000110000, // V
  128. 0b0010100000110110, // W
  129. 0b0010110100000000, // X
  130. 0b0001010100000000, // Y
  131. 0b0010010000001001, // Z
  132. 0b0000000000000000, //
  133. 0b0000000000000110, // 1
  134. 0b0000000011011011, // 2
  135. 0b0000000011001111, // 3
  136. 0b0000000011100110, // 4
  137. 0b0000000011101101, // 5
  138. 0b0000000011111101, // 6
  139. 0b0000000000000111, // 7
  140. 0b0000000011111111, // 8
  141. 0b0000000011101111, // 9
  142. 0b0010010000111111, // 0
  143. 0b0000000000111001, // (
  144. 0b0000000000001111, // )
  145. 0b0000110000000000, // <
  146. 0b0010000100000000, // >
  147. 0b0000010000000000, // '
  148. 0b0101010000100001, // ?
  149. 0b0100000000000000, // .
  150. 0b0000001010111011, // @
  151. 0b0010010000100100, // %
  152. 0b0001001011101101, // $
  153. 0b0000101101011101, // &
  154. 0b0010010000000000, // /
  155. 0b0001001011000000, // +
  156. 0b0000000011000000, // -
  157. 0b0000000011001000, // =
  158. 0b0000000000001000, // _
  159. 0b0001001000000000, // :
  160. 0b0010001000000000, // ;
  161. 0b0010000000000000, // ,
  162. 0b0011111111000000, // *
  163. 0b0000010010000010, // °
  164. };
  165.  
  166. // Tableau pour recevoir ce qui est à afficher ------------------------------------------------------------
  167.  
  168. unsigned long CLaff[4] = {0b0001001000000000, 0b0001000001010000, 0b0001000000000000, 0b0100000001111000};
  169.  
  170. // Valeurs initiales : Init. ------------------------------------------------------------------------------
  171. // (
  172. // 0b0001001000000000 : I
  173. // 0b0001000001010000 : n
  174. // 0b0001000000000000 : i
  175. // 0b0100000001111000 : t.
  176. // )
  177.  
  178. // --------------------------------------------------------------------------------------------------------
  179.  
  180. bool receptionSerial = 0; // Variable qui indique si la réception est en cours ou pas
  181.  
  182. char valeurSerial; // Variable qui prend la valeur du caractere reçu
  183.  
  184. // --------------------------------------------------------------------------------------------------------
  185.  
  186.  
  187. // --------------------------------------------------------------------------------------------------------
  188. // - SET UP -------------------------------------------------------------------------------------- SET UP -
  189. // --------------------------------------------------------------------------------------------------------
  190.  
  191. void setup()
  192. {
  193. Serial.begin(9600); // on initialise la communication entre le PC et Arduino
  194. alpha4.begin(0x70); // on entre l'adresse de l'afficheur en I2C
  195.  
  196. // on note et affiche Init. pour marquer l'initialisation...
  197. affiche ();
  198. }
  199.  
  200. // --------------------------------------------------------------------------------------------------------
  201. // - LOOP ------------------------------------------------------------------------------------------ LOOP -
  202. // --------------------------------------------------------------------------------------------------------
  203.  
  204. void loop()
  205. {
  206.  
  207. lectureSerial ();
  208.  
  209. }
  210.  
  211. // --------------------------------------------------------------------------------------------------------
  212. // - Fonctions -------------------------------------------------------------------------------- Fonctions -
  213. // --------------------------------------------------------------------------------------------------------
  214.  
  215. // Sert à afficher une séquence bien définie, ici, c'est Init. --------------------------------------------
  216. void affiche () {
  217. for (int i = 0; i < 4; i++) {
  218. alpha4.writeDigitRaw (CL[i], uint16_t (CLaff[i]));
  219. Serial.println(CL[i]);
  220. Serial.println(uint16_t (CLaff[i]));
  221. }
  222. alpha4.writeDisplay();
  223. delay(1000);
  224. alpha4.clear();
  225. alpha4.writeDisplay();
  226. delay(250);
  227. }
  228.  
  229. // Sert à afficher une phrase entière et la faire défiler si elle fait plus de 4 caractères ---------------
  230. void affiche4caracteres () {
  231. for (int i = 0; i < 4; i++) {
  232. char aff = texteBrut.charAt (i);
  233.  
  234. Serial.write ("Caractère ");
  235. Serial.print (i + 1);
  236. Serial.write (" : ");
  237. Serial.println (aff);
  238.  
  239. for (int j = 0; j < sizeof(alphaB); j ++) {
  240. if ( alphaB[j] == aff ) {
  241. alpha4.writeDigitRaw (CL[i], uint16_t (alphaB_0b00[j]));
  242. alpha4.writeDisplay();
  243.  
  244. Serial.write ("Afficheur : ");
  245. Serial.println (CL[i]);
  246. Serial.write ("0b00 : ");
  247. Serial.println (uint16_t (alphaB_0b00[j]));
  248.  
  249. }
  250. }
  251. }
  252. delay(200);
  253. alpha4.clear();
  254. alpha4.writeDisplay();
  255. delay(1);
  256.  
  257. }
  258.  
  259. // Sert à afficher une séquence de 4 caractères définis ---------------------------------------------------
  260. void affichePhrase () {
  261. texteTotal = " " + texteTotal;
  262. for (int k = 0; k < texteTotal.length(); k ++) {
  263. texteBrut = texteTotal.substring(k, k + 4);
  264. if (texteBrut != " ") {
  265. Serial.write ("texteBrut : ");
  266. Serial.println (texteBrut);
  267. affiche4caracteres ();
  268. }
  269. }
  270. }
  271.  
  272. void lectureSerial (){
  273. if ( Serial.available() ) { // Tourne tant qu'il reçoit des données
  274. valeurSerial = Serial.read(); // on lit le caractère reçu
  275. if (receptionSerial == 0){ // Si la réception n'était pas en cours
  276. texteTotal = ""; // on vide la variable du texte à afficher
  277. receptionSerial = 1; // on note la réception en cours
  278. }
  279. texteTotal = texteTotal + valeurSerial; // le caractère reçu s'ajoute au message à afficher
  280. Serial.println(valeurSerial); // Le moniteur série affiche la valeur de valeurSerial
  281. Serial.println(texteTotal); // Le moniteur série affiche la valeur de texteTotal
  282. } else { // Si il ne reçoit rien
  283. Serial.println("Rien"); // Le moniteur série affiche "Rien"
  284. receptionSerial = 0; // on note la réception NON en cours
  285. affichePhrase (); // on appelle la fonction d'affichage de phrase (ci-dessus)
  286. }
  287. }
  288. // --------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement