ENIB 2020: I morse

De Les Fabriques du Ponant
Aller à : navigation, rechercher

photo de l'équipe

Bon.png

Projet de Tom, Carole, Aude, Sarah et Titouan.

Que fait ce projet ?

Le projet I-morse va permettre de traduire et d'afficher des messages à partir du langage morse. Le morse est un langage basé sur des impulsions courtes et longues, environ 1 seconde et 2 secondes, chaque caractère est défini par une suite de point et de trait, comme ci-dessous : I-morse.png

Pour écrire un texte, il faut réaliser les lettres les unes après les autres, ceci à l'aide du bouton "start" en rose qui converti les impulsions en lettre. A la fin de chaque lettre, il faut réaliser une impulsion courte sur le bouton "pass" en bleu. Pour passer au mot suivant, il faut réaliser une impulsion courte sur le bouton "pass" afin de valider sa lettre puis une impulsion longue pour réaliser un espace.

Liste des composants

  • Boite "i-morse" réalisé avec la découpeuse laser
  • 2 boutons poussoirs
  • Ecran grove-LCD RGB backlight V4.0
  • Carte arduino UNO
  • Pile 9V pour alimenter la carte arduino
  • Plaque labtech, redboard
  • 2 résistances de 270 ohm

Code

#include <rgb_lcd.h>

/* Inclusion de la bibliothèque standard */
#include <stdlib.h>

/* Inclusion de la bibliothèque des booléens */
#include <stdbool.h>

/* Inclusion de la bibliothèque de l'écran LCD */
#include <LiquidCrystal.h>




rgb_lcd ecranRGB;

int BP1 = 7;
int BP2 = 8;
int temps;
bool pt = LOW;
bool tr = LOW;
bool nx = LOW;
char test[6] = {};
int t;
int oldt;
char point = '.';
char trait = '_';
char next = 'n';
char A[] = {point, trait, next};
char B[] = {trait, point, point, point, next};
char C[] = {trait, point, trait, point, next};
char D[] = {trait, point, point, next};
char E[] = {point, next};
char F[] = {point, point, trait, point, next};
char G[] = {trait, trait, point, next};
char H[] = {point, point, point, point, next};
char I[] = {point, point, next};
char J[] = {point, trait, trait, trait, next};
char K[] = {trait, point, trait, next};
char L[] = {point, trait, point, point, next};
char M[] = {trait, trait, next};
char N[] = {trait, point, next};
char O[] = {trait, trait, trait, next};
char P[] = {point, trait, trait, point, next};
char Q[] = {trait, trait, point, trait, next};
char R[] = {point, trait, point, next};
char S[] = {point, point, point, next};
char T[] = {trait, next};
char U[] = {point, point, trait, next};
char V[] = {point, point, point, trait, next};
char W[] = {point, trait, trait, next};
char X[] = {trait, point, point, trait, next};
char Y[] = {trait, point, trait, trait, next};
char Z[] = {trait, trait, point, point, next};
char n1[] = {point, trait, trait, trait, trait, next};
char n2[] = {point, point, trait, trait, trait, next};
char n3[] = {point, point, point, trait, trait, next};
char n4[] = {point, point, point, point, trait, next};
char n5[] = {point, point, point, point, point, next};
char n6[] = {trait, point, point, point, point, next};
char n7[] = {trait, trait, point, point, point, next};
char n8[] = {trait, trait, trait, point, point, next};
char n9[] = {trait, trait, trait, trait, point, next};
char n0[] = {trait, trait, trait, trait, trait, next};

/* Définition de la structure d'association tableau de signaux / lettre */
typedef struct
{
  unsigned char caracter;
  char signals[7];
} morseCaracter;

static morseCaracter alphabet[] = {{'A', A}, {'B', B}, {'C', C}, {'D', D}, {'E', E}, {'F', F}, {'G', G}, {'H', H}, {'I', I}, {'J', J}, {'K', K}, {'L', L}, {'M', M}, {'N', N}, {'O', O}, {'P', P}, {'Q', Q}, {'R', R}, {'S', S}, {'T', T}, {'U', U}, {'V', V}, {'W', W}, {'X', X}, {'Y', Y}, {'Z', Z}};

void setup() {
  pinMode(BP1, INPUT);
  pinMode(BP2, INPUT);
  ecranRGB.begin(16, 2, 0x00);
  ecranRGB.clear();
  ecranRGB.setCursor(4, 0);
  ecranRGB.print("i_morse");
  Serial.begin(9600);
}

void symbole() {
  t = millis();
  while (digitalRead(BP1) == HIGH) {
  }
  delay(200);
  oldt = t;
  t = millis();
  temps = t - oldt;
  Serial.println(temps);
  if (temps > 800) {
    tr = HIGH;
    Serial.println("trait haut");
  }
  else if (temps > 350) {
    pt = HIGH;
    Serial.println("point haut");
  }
}

void nextfunc() {
  nx = LOW;
  if (digitalRead(BP2) == HIGH) {
    nx = HIGH;
  }
}

void loop() {
  for (int i = 0; i < 6; i++)
  {
    test[i] = NULL;
  }
  nextfunc();
  while (nx == LOW) {
    for (int i = 0; i < 6; i++) {
      while (test[i] == NULL) {
        symbole();
        nextfunc();
        if (tr == HIGH) {
          test[i] = trait;
          Serial.println("tr");
          tr = LOW;
        }
        if (pt == HIGH) {
          test[i] = point;
          Serial.println("pt");
          pt = LOW;
        }
        if (nx == HIGH) {
          test[i] = next;
          i = 6;
        }
      }
    }
  }

  /*for (int i = 0; i < 27; i++) {
    bool lettre = true;
    for (int j = 0; j < 8; j++) {
      Serial.println(char(test[j]));
      Serial.println(char(alphabet[i].signals[j]));
      if ((char(alphabet[i].signals[j]) == char(test[j])) && (lettre == true)) {
        lettre = true;
      }
      else lettre = false;
    }
    if (lettre == true) {
      Serial.println(char(alphabet[i].caracter));
      break;
    }

    }*/
  if (test[0] == point) {
    if (test[1] == next) {
      ecranRGB.clear();
      ecranRGB.setCursor(4, 0);
      ecranRGB.print("i_morse");
      ecranRGB.setCursor(0, 1);
      ecranRGB.print('E');
    }
    else if (test[1] == trait) {
      if (test[2] == next) {
        ecranRGB.clear();
        ecranRGB.setCursor(4, 0);
        ecranRGB.print("i_morse");
        ecranRGB.setCursor(0, 1);
        ecranRGB.print('A');
      }
    }
    else if (test[1] == point) {
      if (test[2] == next) {
        ecranRGB.clear();
        ecranRGB.setCursor(4, 0);
        ecranRGB.print("i_morse");
        ecranRGB.setCursor(0, 1);
        ecranRGB.print('I');
      }
      else if (test[2] == point) {
        if (test[3] == next) {
          ecranRGB.clear();
          ecranRGB.setCursor(4, 0);
          ecranRGB.print("i_morse");
          ecranRGB.setCursor(0, 1);
          ecranRGB.print('S');
        }
      }
      else if (test[2] == trait) {
        if (test[3] == next) {
          ecranRGB.clear();
          ecranRGB.setCursor(4, 0);
          ecranRGB.print("i_morse");
          ecranRGB.setCursor(0, 1);
          ecranRGB.print('U');
        }
      }
    }
  }
  if (test[0] == trait) {
    if (test[1] == next) {
      ecranRGB.clear();
      ecranRGB.setCursor(4, 0);
      ecranRGB.print("i_morse");
      ecranRGB.setCursor(0, 1);
      ecranRGB.print('T');
    }
    else if (test[1] == point) {
      if (test[2] == next) {
        ecranRGB.clear();
        ecranRGB.setCursor(4, 0);
        ecranRGB.print("i_morse");
        ecranRGB.setCursor(0, 1);
        ecranRGB.print('N');
      }
    }
    else if (test[1] == trait) {
      if (test[2] == next) {
        ecranRGB.clear();
        ecranRGB.setCursor(4, 0);
        ecranRGB.print("i_morse");
        ecranRGB.setCursor(0, 1);
        ecranRGB.print('M');
      }
    }
  }
}

Catégories