Répondre à : gestion des caracteres accentués

Forums Les techniques gestion des caracteres accentués Répondre à : gestion des caracteres accentués

#3325
Désiré
Invité

bonjour

Merci Pierre

j’ai résolu mon problème, j’avais oublié de modifier quelques lignes.

Si ça intéresse ce code permet d’envoyer un texte avec un smartphone, il y beaucoup de modèles sur le net, mais rare ceux qui exploite les caractères avec accent.

#include <SoftwareSerial.h>
SoftwareSerial BT(6, 5);

#include <MaxMatrix.h>
#include <avr/pgmspace.h>
#define maxDisplays 1
const int lunghezzafrase = 50;
int contacaratteri = 0;

int contatore = 0;
byte Buf7219[7];

char string [lunghezzafrase];
const int data = 10;
const int load = 9;
const int clock = 8;
MaxMatrix m(data, load, clock, maxDisplays);

PROGMEM const unsigned char CH[] = {
3, 8, B00000000, B00000000, B00000000, B00000000, B00000000, // space
1, 8, B01011111, B00000000, B00000000, B00000000, B00000000, // !
3, 8, B00000011, B00000000, B00000011, B00000000, B00000000, //  »
5, 8, B00010100, B00111110, B00010100, B00111110, B00010100, // #
4, 8, B00100100, B01101010, B00101011, B00010010, B00000000, // $
5, 8, B01100011, B00010011, B00001000, B01100100, B01100011, // %
5, 8, B00110110, B01001001, B01010110, B00100000, B01010000, // &
1, 8, B00000011, B00000000, B00000000, B00000000, B00000000, // ‘
3, 8, B00011100, B00100010, B01000001, B00000000, B00000000, // (
3, 8, B01000001, B00100010, B00011100, B00000000, B00000000, // )
5, 8, B00101000, B00011000, B00001110, B00011000, B00101000, // *
5, 8, B00001000, B00001000, B00111110, B00001000, B00001000, // +
2, 8, B10110000, B01110000, B00000000, B00000000, B00000000, // ,
4, 8, B00001000, B00001000, B00001000, B00001000, B00000000, // –
2, 8, B01100000, B01100000, B00000000, B00000000, B00000000, // .
4, 8, B01100000, B00011000, B00000110, B00000001, B00000000, // /
4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // 0
3, 8, B01000010, B01111111, B01000000, B00000000, B00000000, // 1
4, 8, B01100010, B01010001, B01001001, B01000110, B00000000, // 2
4, 8, B00100010, B01000001, B01001001, B00110110, B00000000, // 3
4, 8, B00011000, B00010100, B00010010, B01111111, B00000000, // 4
4, 8, B00100111, B01000101, B01000101, B00111001, B00000000, // 5
4, 8, B00111110, B01001001, B01001001, B00110000, B00000000, // 6
4, 8, B01100001, B00010001, B00001001, B00000111, B00000000, // 7
4, 8, B00110110, B01001001, B01001001, B00110110, B00000000, // 8
4, 8, B00000110, B01001001, B01001001, B00111110, B00000000, // 9
2, 8, B01010000, B00000000, B00000000, B00000000, B00000000, // :
2, 8, B10000000, B01010000, B00000000, B00000000, B00000000, // ;
3, 8, B00010000, B00101000, B01000100, B00000000, B00000000, // <
3, 8, B00010100, B00010100, B00010100, B00000000, B00000000, // =
3, 8, B01000100, B00101000, B00010000, B00000000, B00000000, // >
4, 8, B00000010, B01011001, B00001001, B00000110, B00000000, // ?
5, 8, B00111110, B01001001, B01010101, B01011101, B00001110, // @
4, 8, B01111110, B00010001, B00010001, B01111110, B00000000, // A
4, 8, B01111111, B01001001, B01001001, B00110110, B00000000, // B
4, 8, B00111110, B01000001, B01000001, B00100010, B00000000, // C
4, 8, B01111111, B01000001, B01000001, B00111110, B00000000, // D
4, 8, B01111111, B01001001, B01001001, B01000001, B00000000, // E
4, 8, B01111111, B00001001, B00001001, B00000001, B00000000, // F
4, 8, B00111110, B01000001, B01001001, B01111010, B00000000, // G
4, 8, B01111111, B00001000, B00001000, B01111111, B00000000, // H
3, 8, B01000001, B01111111, B01000001, B00000000, B00000000, // I
4, 8, B00110000, B01000000, B01000001, B00111111, B00000000, // J
4, 8, B01111111, B00001000, B00010100, B01100011, B00000000, // K
4, 8, B01111111, B01000000, B01000000, B01000000, B00000000, // L
5, 8, B01111111, B00000010, B00001100, B00000010, B01111111, // M
5, 8, B01111111, B00000100, B00001000, B00010000, B01111111, // N
4, 8, B00111110, B01000001, B01000001, B00111110, B00000000, // O
4, 8, B01111111, B00001001, B00001001, B00000110, B00000000, // P
4, 8, B00111110, B01000001, B01000001, B10111110, B00000000, // Q
4, 8, B01111111, B00001001, B00001001, B01110110, B00000000, // R
4, 8, B01000110, B01001001, B01001001, B00110010, B00000000, // S
5, 8, B00000001, B00000001, B01111111, B00000001, B00000001, // T
4, 8, B00111111, B01000000, B01000000, B00111111, B00000000, // U
5, 8, B00001111, B00110000, B01000000, B00110000, B00001111, // V
5, 8, B00111111, B01000000, B00111000, B01000000, B00111111, // W
5, 8, B01100011, B00010100, B00001000, B00010100, B01100011, // X
5, 8, B00000111, B00001000, B01110000, B00001000, B00000111, // Y
4, 8, B01100001, B01010001, B01001001, B01000111, B00000000, // Z
2, 8, B01111111, B01000001, B00000000, B00000000, B00000000, // [
4, 8, B00000001, B00000110, B00011000, B01100000, B00000000, // \ backslash
2, 8, B01000001, B01111111, B00000000, B00000000, B00000000, // ]
3, 8, B00000010, B00000001, B00000010, B00000000, B00000000, // hat
4, 8, B01000000, B01000000, B01000000, B01000000, B00000000, // _
2, 8, B00000001, B00000010, B00000000, B00000000, B00000000, // `
4, 8, B00100000, B01010100, B01010100, B01111000, B00000000, // a
4, 8, B01111111, B01000100, B01000100, B00111000, B00000000, // b
4, 8, B00111000, B01000100, B01000100, B00101000, B00000000, // c
4, 8, B00111000, B01000100, B01000100, B01111111, B00000000, // d
4, 8, B00111000, B01010100, B01010100, B00011000, B00000000, // e
3, 8, B00000100, B01111110, B00000101, B00000000, B00000000, // f
4, 8, B10011000, B10100100, B10100100, B01111000, B00000000, // g
4, 8, B01111111, B00000100, B00000100, B01111000, B00000000, // h
3, 8, B01000100, B01111101, B01000000, B00000000, B00000000, // i
4, 8, B01000000, B10000000, B10000100, B01111101, B00000000, // j
4, 8, B01111111, B00010000, B00101000, B01000100, B00000000, // k
3, 8, B01000001, B01111111, B01000000, B00000000, B00000000, // l
5, 8, B01111100, B00000100, B01111100, B00000100, B01111000, // m
4, 8, B01111100, B00000100, B00000100, B01111000, B00000000, // n
4, 8, B00111000, B01000100, B01000100, B00111000, B00000000, // o
4, 8, B11111100, B00100100, B00100100, B00011000, B00000000, // p
4, 8, B00011000, B00100100, B00100100, B11111100, B00000000, // q
4, 8, B01111100, B00001000, B00000100, B00000100, B00000000, // r
4, 8, B01001000, B01010100, B01010100, B00100100, B00000000, // s
3, 8, B00000100, B00111111, B01000100, B00000000, B00000000, // t
4, 8, B00111100, B01000000, B01000000, B01111100, B00000000, // u
5, 8, B00011100, B00100000, B01000000, B00100000, B00011100, // v
5, 8, B00111100, B01000000, B00111100, B01000000, B00111100, // w
5, 8, B01000100, B00101000, B00010000, B00101000, B01000100, // x
4, 8, B10011100, B10100000, B10100000, B01111100, B00000000, // y
3, 8, B01100100, B01010100, B01001100, B00000000, B00000000, // z
3, 8, B00001000, B00110110, B01000001, B00000000, B00000000, // {
1, 8, B01111111, B00000000, B00000000, B00000000, B00000000, // |
3, 8, B01000001, B00110110, B00001000, B00000000, B00000000, // }
4, 8, B00001000, B00000100, B00001000, B00000100, B00000000, // ~
1, 8, B00000000, B00000000, B00000000, B00000000, B00000000, // DEL (unused)
4, 8, B00111110, B01000001, B11000001, B00100010, B00000000, // Ç 96
4, 8, B00111100, B01000001, B01000000, B01111100, B00000000, // ü 97
4, 8, B00111000, B01010110, B01010101, B00011000, B00000000, // é 98
4, 8, B00100000, B01010110, B01010101, B01111010, B00000000, // â 99
4, 8, B00100000, B01010101, B01010100, B01111001, B00000000, // ä 100
4, 8, B00100000, B01010101, B01010110, B01111000, B00000000, // à 101
4, 8, B00100000, B01010100, B01010100, B01111000, B00000000, // å 102
4, 8, B00111010, B01010101, B01010101, B00011010, B00000000, // ê 103
4, 8, B00111000, B01010101, B01010100, B00011001, B00000000, // ë 104
4, 8, B00111000, B01010101, B01010110, B00011000, B00000000, // è 105
3, 8, B01000101, B01111100, B01000001, B00000000, B00000000, // ï 106
3, 8, B01000110, B01111101, B01000010, B00000000, B00000000 // î 107
};

void printCharWithShift(char c, int shift_speed){
int char_indice = 0;
Serial.print(« c1 = « );
Serial.println(c);
Serial.print(« c1 hexa = « );
Serial.println(c,HEX);

// Switch pour gestion des caracteres accentués
switch (c) {
case 0XFFFFFFC3:
break;
case 0XFFFFFFA0 :
char_indice= 101; // à
break;
case 0XFFFFFFA9:
char_indice=98; // é
break;
case 0XFFFFFFA8 :
char_indice=105; // è
break;
case 0XFFFFFFAA:
char_indice=103; // ê
break;
case 0XFFFFFFAB :
char_indice=104; // ë
break;
case 0XFFFFFFA4 :
char_indice=100; // ä
break;
case 0XFFFFFFAE:
char_indice=107; // î
break;
case 0XFFFFFFA2:
char_indice=99; // â
break;
case 0XFFFFFFAF:
char_indice=106; // ï
}

if ((c < 32)&&(char_indice == 0)) return;
if ((c < 127)&&(char_indice == 0)) char_indice = c – 32;

memcpy_P(Buf7219, CH + 7*char_indice, 7);
m.writeSprite(maxDisplays * 8, 0, Buf7219);
m.setColumn(maxDisplays * 8 + Buf7219[0], 0);

for (int i=0; i<Buf7219[0]+1; i++)
{
delay(shift_speed);
m.shiftLeft(false, false);
}
}

void printStringWithShift(char* s, int shift_speed){
contatore = 0;
while (*s != 0){
printCharWithShift(*s, shift_speed);
s++;
contatore++;
if (contatore > contacaratteri)
return;
}
}

void setup()
{
m.init();
m.setIntensity(3);
Serial.begin(9600);
BT.begin(9600);
}
void loop()
{

if (BT.available())
{
for (contacaratteri = 0; contacaratteri <= lunghezzafrase; contacaratteri++)
{

if (!(Serial.available ()))
string [contacaratteri] = BT.read();

if (!(BT.available ())) return;
}
}
else
{
delay(100);
m.shiftLeft(false, true);
printStringWithShift (string, 150);

}
}