Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // -----------------------------------------------------------------------------------------------------
- // Affichage et de défilement d'un texte | Afficheur à LED 4 Digit Alphanumérique Octopus EF04058
- // avec saisie clavier transmise par port serie
- // http://www.elecfreaks.com/wiki/index.php?title=Octopus_Alphanumeric_LED_Brick
- // https://learn.adafruit.com/adafruit-led-backpack/0-54-alphanumeric
- // =====================================================================================================
- // =====================================================================================================
- // Branchements I2C/Wire
- // =====================================================================================================
- // GRD => Grd
- // VCC => 5 V
- // SDA => SDA / A4
- // SCL => SCL / A5
- // =====================================================================================================
- // =====================================================================================================
- // Disposition des segments
- // =====================================================================================================
- // ---- A ----
- // | \ | / |
- // F H J K B
- // | \ | / |
- // |-G1- | -G2-|
- // | / | \ |
- // E L M N C
- // | / | \ |
- // ---- D ---- (DP)
- //
- // ... ou dans mon cas :
- //
- // ---- A ----
- // | \ | / |
- // F H J K B
- // | \ | / |
- // |-G1- | -G2-|
- // | / | \ |
- // E (N) M (L) C
- // | / | \ |
- // ---- D ---- (DP)
- // =====================================================================================================
- // Chargement des librairies nécessaires ---------------------------------------------------------------
- #include <Wire.h> // Librairie de cablage simplifié (??)
- #include "Adafruit_LEDBackpack.h" // Librairie d'affichage sur ecran LCD
- #include "Adafruit_GFX.h" // Librairie d'affichage graphique
- // Déclaration de l'objet alpha4 -----------------------------------------------------------------------
- Adafruit_AlphaNum4 alpha4 = Adafruit_AlphaNum4();
- // Déclaration de la variable contenant la phrase à afficher -------------------------------------------
- // ATTENTION pas d'accent, pas de €, ni de ! désolé ----------------------------------------------------
- String texteTotal = "Ouvrez la console serie et saisissez le texte a afficher";
- // Déclaration de la variable contenant la séquence à afficher -----------------------------------------
- // initialement "zoll" même ça ne sert pas -------------------------------------------------------------
- String texteBrut = "zoll";
- // Détermination de l'ordre des blocs d'affichage. (Parce que mon afficheur est mal monté, je pense, ------
- // M et K sont inversés) et les deux modules de d'affichages eux-même le sont -----------------------------
- int CL[4] = {2, 3, 0, 1};
- // Remarque : J'aurais pu corriger le fichier Adafruit_LEDBackoack.cpp et utiliser la fonction ------------
- // alpha4.writeDigitAscii (). -----------------------------------------------------------------------------
- // Tableau qui contient l'alphabet ------------------------------------------------------------------------
- char alphaB[84] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890()<>'?.@%$&/+-=_:;,*°";
- // Tableau qui contient l'alphabet en 0b00 auquel correspond le tableau de l'alphabet ---------------------
- const unsigned long alphaB_0b00 [84] = {
- 0b0001000001011000, // a
- 0b0000100001111000, // b
- 0b0000000011011000, // c
- 0b0000000011011110, // d
- 0b0010000001011000, // e
- 0b0000000001110001, // f
- 0b0000000110001111, // g
- 0b0000100001110000, // h
- 0b0001000000000000, // i
- 0b0000000000001110, // j
- 0b0001111000000000, // k
- 0b0001001000000000, // l
- 0b0001000011010100, // m
- 0b0001000001010000, // n
- 0b0000000011011100, // o
- 0b0000000011110011, // p
- 0b0000000110000111, // q
- 0b0000000001010000, // r
- 0b0000100010001000, // s
- 0b0000000001111000, // t
- 0b0000000000011100, // u
- 0b0010000000010000, // v
- 0b0010100000010100, // w
- 0b0010100011000000, // x
- 0b0010001001100000, // y
- 0b0010000001001000, // z
- 0b0000000011110111, // A
- 0b0001001010001111, // B
- 0b0000000000111001, // C
- 0b0001001000001111, // D
- 0b0000000011111001, // E
- 0b0000000011110001, // F
- 0b0000000010111101, // G
- 0b0000000011110110, // H
- 0b0001001000000000, // I
- 0b0000000000011110, // J
- 0b0000110001110000, // K
- 0b0000000000111000, // L
- 0b0000010100110110, // M
- 0b0000100100110110, // N
- 0b0000000000111111, // O
- 0b0000000011110011, // P
- 0b0000100000111111, // Q
- 0b0000100011110011, // R
- 0b0000000011101101, // S
- 0b0001001000000001, // T
- 0b0000000000111110, // U
- 0b0010010000110000, // V
- 0b0010100000110110, // W
- 0b0010110100000000, // X
- 0b0001010100000000, // Y
- 0b0010010000001001, // Z
- 0b0000000000000000, //
- 0b0000000000000110, // 1
- 0b0000000011011011, // 2
- 0b0000000011001111, // 3
- 0b0000000011100110, // 4
- 0b0000000011101101, // 5
- 0b0000000011111101, // 6
- 0b0000000000000111, // 7
- 0b0000000011111111, // 8
- 0b0000000011101111, // 9
- 0b0010010000111111, // 0
- 0b0000000000111001, // (
- 0b0000000000001111, // )
- 0b0000110000000000, // <
- 0b0010000100000000, // >
- 0b0000010000000000, // '
- 0b0101010000100001, // ?
- 0b0100000000000000, // .
- 0b0000001010111011, // @
- 0b0010010000100100, // %
- 0b0001001011101101, // $
- 0b0000101101011101, // &
- 0b0010010000000000, // /
- 0b0001001011000000, // +
- 0b0000000011000000, // -
- 0b0000000011001000, // =
- 0b0000000000001000, // _
- 0b0001001000000000, // :
- 0b0010001000000000, // ;
- 0b0010000000000000, // ,
- 0b0011111111000000, // *
- 0b0000010010000010, // °
- };
- // Tableau pour recevoir ce qui est à afficher ------------------------------------------------------------
- unsigned long CLaff[4] = {0b0001001000000000, 0b0001000001010000, 0b0001000000000000, 0b0100000001111000};
- // Valeurs initiales : Init. ------------------------------------------------------------------------------
- // (
- // 0b0001001000000000 : I
- // 0b0001000001010000 : n
- // 0b0001000000000000 : i
- // 0b0100000001111000 : t.
- // )
- // --------------------------------------------------------------------------------------------------------
- bool receptionSerial = 0; // Variable qui indique si la réception est en cours ou pas
- char valeurSerial; // Variable qui prend la valeur du caractere reçu
- // --------------------------------------------------------------------------------------------------------
- // --------------------------------------------------------------------------------------------------------
- // - SET UP -------------------------------------------------------------------------------------- SET UP -
- // --------------------------------------------------------------------------------------------------------
- void setup()
- {
- Serial.begin(9600); // on initialise la communication entre le PC et Arduino
- alpha4.begin(0x70); // on entre l'adresse de l'afficheur en I2C
- // on note et affiche Init. pour marquer l'initialisation...
- affiche ();
- }
- // --------------------------------------------------------------------------------------------------------
- // - LOOP ------------------------------------------------------------------------------------------ LOOP -
- // --------------------------------------------------------------------------------------------------------
- void loop()
- {
- lectureSerial ();
- }
- // --------------------------------------------------------------------------------------------------------
- // - Fonctions -------------------------------------------------------------------------------- Fonctions -
- // --------------------------------------------------------------------------------------------------------
- // Sert à afficher une séquence bien définie, ici, c'est Init. --------------------------------------------
- void affiche () {
- for (int i = 0; i < 4; i++) {
- alpha4.writeDigitRaw (CL[i], uint16_t (CLaff[i]));
- Serial.println(CL[i]);
- Serial.println(uint16_t (CLaff[i]));
- }
- alpha4.writeDisplay();
- delay(1000);
- alpha4.clear();
- alpha4.writeDisplay();
- delay(250);
- }
- // Sert à afficher une phrase entière et la faire défiler si elle fait plus de 4 caractères ---------------
- void affiche4caracteres () {
- for (int i = 0; i < 4; i++) {
- char aff = texteBrut.charAt (i);
- Serial.write ("Caractère ");
- Serial.print (i + 1);
- Serial.write (" : ");
- Serial.println (aff);
- for (int j = 0; j < sizeof(alphaB); j ++) {
- if ( alphaB[j] == aff ) {
- alpha4.writeDigitRaw (CL[i], uint16_t (alphaB_0b00[j]));
- alpha4.writeDisplay();
- Serial.write ("Afficheur : ");
- Serial.println (CL[i]);
- Serial.write ("0b00 : ");
- Serial.println (uint16_t (alphaB_0b00[j]));
- }
- }
- }
- delay(200);
- alpha4.clear();
- alpha4.writeDisplay();
- delay(1);
- }
- // Sert à afficher une séquence de 4 caractères définis ---------------------------------------------------
- void affichePhrase () {
- texteTotal = " " + texteTotal;
- for (int k = 0; k < texteTotal.length(); k ++) {
- texteBrut = texteTotal.substring(k, k + 4);
- if (texteBrut != " ") {
- Serial.write ("texteBrut : ");
- Serial.println (texteBrut);
- affiche4caracteres ();
- }
- }
- }
- void lectureSerial (){
- if ( Serial.available() ) { // Tourne tant qu'il reçoit des données
- valeurSerial = Serial.read(); // on lit le caractère reçu
- if (receptionSerial == 0){ // Si la réception n'était pas en cours
- texteTotal = ""; // on vide la variable du texte à afficher
- receptionSerial = 1; // on note la réception en cours
- }
- texteTotal = texteTotal + valeurSerial; // le caractère reçu s'ajoute au message à afficher
- Serial.println(valeurSerial); // Le moniteur série affiche la valeur de valeurSerial
- Serial.println(texteTotal); // Le moniteur série affiche la valeur de texteTotal
- } else { // Si il ne reçoit rien
- Serial.println("Rien"); // Le moniteur série affiche "Rien"
- receptionSerial = 0; // on note la réception NON en cours
- affichePhrase (); // on appelle la fonction d'affichage de phrase (ci-dessus)
- }
- }
- // --------------------------------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement