initial commit
This commit is contained in:
parent
8c86d57a5b
commit
e1ac1fe72b
3 changed files with 739 additions and 0 deletions
251
reborn/dekalo_reborn.ino
Normal file
251
reborn/dekalo_reborn.ino
Normal file
|
@ -0,0 +1,251 @@
|
|||
#include <FastLED.h>
|
||||
|
||||
|
||||
//fastled
|
||||
#define NUM_LEDS 200 //7 * 9 * 2 + 2*2(points)
|
||||
#define DATA_PIN 3
|
||||
CRGB leds[NUM_LEDS]; // Define the array of leds
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
//Serial
|
||||
Serial.begin(9600);
|
||||
|
||||
//FASTLED
|
||||
FastLED.addLeds<WS2811, DATA_PIN, GRB>(leds, NUM_LEDS);
|
||||
|
||||
//RAZ de l'afficheur
|
||||
sevensegment(String(" "), 1, false);
|
||||
|
||||
//serial envoyage de chiffres
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void sevensegment(String displayString, short displayColor, bool displayPoints) //2 strings
|
||||
{
|
||||
|
||||
//Serial.println("Entrée dans sevensegment");
|
||||
|
||||
//RAZ
|
||||
for(int i=0; i<140; i++)
|
||||
{
|
||||
leds[i] = CRGB::Black;
|
||||
}
|
||||
|
||||
//transformer le string en une matrice de 9caractères
|
||||
|
||||
int numSpaces = 9 - displayString.length();
|
||||
|
||||
for(int i=0; i<numSpaces; i++)
|
||||
{
|
||||
displayString = " " + displayString;
|
||||
}
|
||||
|
||||
char displayText[10];
|
||||
displayString.toCharArray(displayText, 10);
|
||||
|
||||
//Serial.println (displayText);
|
||||
|
||||
|
||||
//transformer la matrice de caracteres en une matrice de numéros
|
||||
//avec
|
||||
//char 0 = 0
|
||||
//char 1 = 1
|
||||
//etc
|
||||
//char - = 10
|
||||
int displayNumCode[9];
|
||||
|
||||
for(int i=0; i<9; i++)
|
||||
{
|
||||
switch (displayText[i])
|
||||
{
|
||||
case '0':displayNumCode[i] = 0;break;
|
||||
case '1':displayNumCode[i] = 1;break;
|
||||
case '2':displayNumCode[i] = 2;break;
|
||||
case '3':displayNumCode[i] = 3;break;
|
||||
case '4':displayNumCode[i] = 4;break;
|
||||
case '5':displayNumCode[i] = 5;break;
|
||||
case '6':displayNumCode[i] = 6;break;
|
||||
case '7':displayNumCode[i] = 7;break;
|
||||
case '8':displayNumCode[i] = 8;break;
|
||||
case '9':displayNumCode[i] = 9;break;
|
||||
case '-':displayNumCode[i] = 10;break;
|
||||
case ' ':displayNumCode[i] = 11;break;
|
||||
}
|
||||
}
|
||||
|
||||
//afficher l'array displayNumCode
|
||||
/*
|
||||
Serial.print("DisplayNumCode = ( ");
|
||||
for(int i=0; i<9; i++)
|
||||
{
|
||||
Serial.print(displayNumCode[i]);
|
||||
Serial.print(",");
|
||||
}
|
||||
Serial.println(" )");
|
||||
*/
|
||||
//l'ordre des leds est inverse au sens d'écriture des chiffres.
|
||||
//il faut donc inverser l'array de displayNumCode.
|
||||
|
||||
int displayNumCodeReversed[9]; //taille 8 ou 9 ?
|
||||
for(int i=0; i<9; i++)
|
||||
{
|
||||
displayNumCodeReversed[8-i] = displayNumCode[i];
|
||||
}
|
||||
|
||||
//afficher l'array displayNumCodeReversed
|
||||
|
||||
/*
|
||||
Serial.print("DisplayNumCodeReversed = ( ");
|
||||
for(int i=0; i<9; i++)
|
||||
{
|
||||
Serial.print(displayNumCodeReversed[i]);
|
||||
Serial.print(",");
|
||||
}
|
||||
Serial.println(" )");
|
||||
*/
|
||||
|
||||
//quels segments allumer pour chaque caractere
|
||||
// 2
|
||||
// ___
|
||||
// 3| |1
|
||||
// |_4_|
|
||||
// 7| |5
|
||||
// |___|
|
||||
// 6
|
||||
|
||||
// à revoir
|
||||
int matrixsevenseg[12][7] = //12 charactères, 012345679-" ", 7 seg
|
||||
// 1 2 3 4 5 6 7
|
||||
{ {1,1,1,0,1,1,1}, //char 0
|
||||
{1,0,0,0,1,0,0}, //char 1
|
||||
{1,1,0,1,0,1,1}, //char 2
|
||||
{1,1,0,1,1,1,0}, //char 3
|
||||
{1,0,1,1,1,0,0}, //char 4
|
||||
{0,1,1,1,1,1,0}, //char 5
|
||||
{0,1,1,1,1,1,1}, //char 6
|
||||
{1,1,0,0,1,0,0}, //char 7
|
||||
{1,1,1,1,1,1,1}, //char 8
|
||||
{1,1,1,1,1,1,0}, //char 9
|
||||
{0,0,0,1,0,0,0}, //char -
|
||||
{0,0,0,0,0,0,0} //char " " (space)
|
||||
};
|
||||
|
||||
int test[132]={0};
|
||||
//Serial.println("Déclaré la matrice des segments 'matrixsevenseg' ");
|
||||
//afficher les caracteres individuels
|
||||
|
||||
for(int i=0; i<=8; i++) //chaque caractère
|
||||
{
|
||||
//Serial.print("on entre dans le caractère n°");
|
||||
//Serial.print(i);
|
||||
//Serial.print(". On cherche à afficher le caractère : ");
|
||||
//Serial.println(displayNumCodeReversed[i]);
|
||||
for(int j = 0; j<7; j++) //chaque segment
|
||||
{
|
||||
//Serial.print("on entre dans le segment n°");
|
||||
//Serial.print(j);
|
||||
//Serial.print(" Ce segment doit avoir pour valeur : ");
|
||||
//Serial.println(matrixsevenseg[displayNumCodeReversed[i]][j]);
|
||||
|
||||
|
||||
if(matrixsevenseg[displayNumCodeReversed[i]][j] == 1)
|
||||
{
|
||||
for(int k=0; k<2; k++) // les 2 leds du segemnt
|
||||
{
|
||||
//Serial.print("indice : ");
|
||||
//Serial.print(i*7*2 +(j)*2 + k);
|
||||
|
||||
if(matrixsevenseg[displayNumCodeReversed[i]][j] == 1)
|
||||
{
|
||||
if(displayColor == 1){leds[i*7*2 +(j)*2 + k] = CRGB::Red;}
|
||||
else if(displayColor == 2){leds[i*7*2 +(j)*2 + k] = CRGB::Blue;}
|
||||
else if(displayColor == 3){leds[i*7*2 +(j)*2 + k] = CRGB::Green;}
|
||||
else if(displayColor == 4){leds[i*7*2 +(j)*2 + k] = CRGB::Yellow;}
|
||||
else if(displayColor == 5){leds[i*7*2 +(j)*2 + k] = CRGB::Pink;}
|
||||
|
||||
//test[i*7*2 +(j)*2 + k] = 19;
|
||||
//Serial.println(" -> on");
|
||||
}
|
||||
else
|
||||
{
|
||||
leds[i*7*2 +(j)*2 + k] = CRGB::Black;
|
||||
//test[i*7*2 +(j)*2 + k] = 2;
|
||||
//Serial.println(" -> off");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//points
|
||||
|
||||
if(displayPoints == true)
|
||||
{
|
||||
//éteindre les points
|
||||
for(int m=126; m<=140; m++)
|
||||
{
|
||||
if(displayColor == 1){leds[m] = CRGB::Red;}
|
||||
else if(displayColor == 2){leds[m] = CRGB::Blue;}
|
||||
else if(displayColor == 3){leds[m] = CRGB::Green;}
|
||||
else if(displayColor == 4){leds[m] = CRGB::Yellow;}
|
||||
else if(displayColor == 5){leds[m] = CRGB::Pink;}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//allumer les points
|
||||
for(int m=126; m<=140; m++)
|
||||
{
|
||||
leds[m] = CRGB::Black; //adapter les points à la couleur de displaycolor
|
||||
}
|
||||
}
|
||||
|
||||
FastLED.show();
|
||||
//Serial.println("fastled.show()");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
|
||||
//couleurs :
|
||||
//1 = Red
|
||||
//2 = Blue
|
||||
//3 = Green
|
||||
//4 = Yellow
|
||||
//5 = Pink
|
||||
|
||||
|
||||
String messageStr = "123456789";
|
||||
|
||||
sevensegment(messageStr, 3, true);
|
||||
|
||||
|
||||
if(Serial.available()){
|
||||
Serial.print("Rentrer le nombre à écrire : " );
|
||||
messageStr = Serial.read();
|
||||
Serial.print("Tu as écrit : " );
|
||||
Serial.println(messageStr);
|
||||
sevensegment(messageStr, 1, false);
|
||||
}
|
||||
|
||||
/*
|
||||
for(int i=51*60; i>=0; i--)
|
||||
{
|
||||
sevensegment(String(i), 1, false);
|
||||
delay(1000);
|
||||
}
|
||||
*/
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue