Programme qui permet de piloter un bandeau de LED ring (de la marque adafruit) en fonction du son qui provient d'un microphone externe. Programme fonctionnant sur un microcontrôleur DISCO-F746NG. Ce projet a était fait dans la cadre du cour d'interface de la Licence MECSE de l'IUT de Cachan.
Dependencies: TS_DISCO_F746NG mbed LCD_DISCO_F746NG BSP_DISCO_F746NG NeoPixel BUTTON_GROUP
test
main.cpp@13:075e7b811cc6, 2019-06-04 (annotated)
- Committer:
- marcolasek
- Date:
- Tue Jun 04 12:55:46 2019 +0000
- Revision:
- 13:075e7b811cc6
- Parent:
- 12:e2bb579c4455
version final
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
marcolasek | 13:075e7b811cc6 | 1 | #include "button_group.hpp" |
marcolasek | 13:075e7b811cc6 | 2 | #include "neopixel.h" |
marcolasek | 13:075e7b811cc6 | 3 | |
marcolasek | 13:075e7b811cc6 | 4 | #define N 12 //Nombre de led à gerer |
MikamiUitOpen | 0:35af280527cf | 5 | |
marcolasek | 13:075e7b811cc6 | 6 | NeoPixelOut strip(D1); //Sortie pour le bandeau de led |
marcolasek | 13:075e7b811cc6 | 7 | Serial pc (USBTX, USBRX); //Paramètre pour le debug USB |
marcolasek | 13:075e7b811cc6 | 8 | AnalogIn sound (A0); //Entrée analogique pour le capteur du son |
marcolasek | 13:075e7b811cc6 | 9 | TS_DISCO_F746NG ts_; //Parametre pour le tactile |
marcolasek | 13:075e7b811cc6 | 10 | LCD_DISCO_F746NG lcd_; //Parametre pour l'écran |
MikamiUitOpen | 0:35af280527cf | 11 | |
MikamiUitOpen | 0:35af280527cf | 12 | using namespace Mikami; |
MikamiUitOpen | 0:35af280527cf | 13 | |
marcolasek | 13:075e7b811cc6 | 14 | //Fonctions |
marcolasek | 13:075e7b811cc6 | 15 | void allumeLed(long couleur); //Fonction qui allumer les toutes les leds, elle prends en parametre la couleur à allumer |
marcolasek | 13:075e7b811cc6 | 16 | void allumeLed(long couleur, int i); //Fonction qui allumer les leds de la couleur 1, |
marcolasek | 13:075e7b811cc6 | 17 | //elle prends en parametre la couleur à allumer |
marcolasek | 13:075e7b811cc6 | 18 | //et i etant le numéro de la led à allumer |
marcolasek | 13:075e7b811cc6 | 19 | void eteindreLed(); //Fonction qui eteinds toutes les leds |
marcolasek | 13:075e7b811cc6 | 20 | |
marcolasek | 13:075e7b811cc6 | 21 | |
marcolasek | 13:075e7b811cc6 | 22 | //Variables |
marcolasek | 13:075e7b811cc6 | 23 | float lum = 1.0; //Valeur de la luminosité de 0.1 à 1.0 |
marcolasek | 13:075e7b811cc6 | 24 | long couleur1 = 0x00FF00; //Valeur de la couleur 1 |
marcolasek | 13:075e7b811cc6 | 25 | long couleur2 = 0xFF0000; //Valeur de la couleur 2 |
marcolasek | 13:075e7b811cc6 | 26 | |
MikamiUitOpen | 0:35af280527cf | 27 | |
MikamiUitOpen | 0:35af280527cf | 28 | int main() |
MikamiUitOpen | 0:35af280527cf | 29 | { |
MikamiUitOpen | 0:35af280527cf | 30 | const int Y0 = 5; |
MikamiUitOpen | 6:2736b38c1d73 | 31 | const uint32_t BACK_COLOR = 0xFF006A6C; // teal green |
MikamiUitOpen | 6:2736b38c1d73 | 32 | lcd_.Clear(BACK_COLOR); |
marcolasek | 13:075e7b811cc6 | 33 | |
marcolasek | 13:075e7b811cc6 | 34 | const int NUMBER_BUTTONS = 2; |
marcolasek | 13:075e7b811cc6 | 35 | const string STR[NUMBER_BUTTONS] = {"Mode 1 : Normal", "Mode 2 : Chenillard"}; |
marcolasek | 13:075e7b811cc6 | 36 | ButtonGroup bGroup(lcd_, ts_, 10, Y0+150, 180, 40, |
MikamiUitOpen | 6:2736b38c1d73 | 37 | LCD_COLOR_BLUE, BACK_COLOR, NUMBER_BUTTONS, STR, 5, 5, 3); |
marcolasek | 13:075e7b811cc6 | 38 | bGroup.Draw(0, LCD_COLOR_DARKBLUE); |
MikamiUitOpen | 0:35af280527cf | 39 | |
MikamiUitOpen | 12:e2bb579c4455 | 40 | const string MULTI[2] = {"ON", "OFF"}; |
marcolasek | 13:075e7b811cc6 | 41 | ButtonGroup multiTouch(lcd_, ts_, 10, Y0+70, 60, 40, |
marcolasek | 13:075e7b811cc6 | 42 | LCD_COLOR_BLUE, BACK_COLOR, 2, MULTI, 5, 0, 2); |
marcolasek | 13:075e7b811cc6 | 43 | multiTouch.Draw(1, LCD_COLOR_DARKBLUE); |
MikamiUitOpen | 12:e2bb579c4455 | 44 | |
MikamiUitOpen | 0:35af280527cf | 45 | lcd_.SetTextColor(LCD_COLOR_WHITE); |
MikamiUitOpen | 12:e2bb579c4455 | 46 | lcd_.SetFont(&Font16); |
marcolasek | 13:075e7b811cc6 | 47 | lcd_.DisplayStringAt(10, Y0+50, (uint8_t *)"Activation :", LEFT_MODE); |
marcolasek | 13:075e7b811cc6 | 48 | |
marcolasek | 13:075e7b811cc6 | 49 | int num; //Vairable qui stock la valeur de la touche appuyée |
marcolasek | 13:075e7b811cc6 | 50 | float valeurMicro; //Variable qui sotck la valeur de notre micro |
marcolasek | 13:075e7b811cc6 | 51 | bool start = false; //Variable pour savoir si on est à on ou off |
marcolasek | 13:075e7b811cc6 | 52 | int mode = 1; //Variable pour savoir quel mode est activé |
marcolasek | 13:075e7b811cc6 | 53 | |
marcolasek | 13:075e7b811cc6 | 54 | |
marcolasek | 13:075e7b811cc6 | 55 | |
marcolasek | 13:075e7b811cc6 | 56 | while (true) { |
marcolasek | 13:075e7b811cc6 | 57 | for (int i = 0; i < N ; i++) { //Boucle qui permet d'activer led par led |
marcolasek | 13:075e7b811cc6 | 58 | char str[20]; //Variable qui permet d'afficher sur notre écran |
marcolasek | 13:075e7b811cc6 | 59 | sprintf(str,"Son : %f", 0.00); //On affiche la valeur 0 |
marcolasek | 13:075e7b811cc6 | 60 | lcd_.SetFont(&Font20); |
MikamiUitOpen | 12:e2bb579c4455 | 61 | |
marcolasek | 13:075e7b811cc6 | 62 | |
marcolasek | 13:075e7b811cc6 | 63 | int mNum; //Variable qui permet de savoir sur quel bouton on a appuyé |
marcolasek | 13:075e7b811cc6 | 64 | if (multiTouch.GetTouchedNumber(mNum, LCD_COLOR_DARKBLUE)) { //Si on a appuyé sur un bouton |
marcolasek | 13:075e7b811cc6 | 65 | Button::SetMultiTouch(mNum == 0); // Set or reset multi-touch |
marcolasek | 13:075e7b811cc6 | 66 | if (mNum == 0) { |
marcolasek | 13:075e7b811cc6 | 67 | //Si on a appuyé sur le bouton On |
marcolasek | 13:075e7b811cc6 | 68 | start = true; //Variable start à true |
marcolasek | 13:075e7b811cc6 | 69 | //lcd_.DisplayStringAt(10, Y0+120, (uint8_t *)"ON ", LEFT_MODE); //On affiche On sur l'ecran |
marcolasek | 13:075e7b811cc6 | 70 | } else { |
marcolasek | 13:075e7b811cc6 | 71 | //Sinon bouton OFF |
marcolasek | 13:075e7b811cc6 | 72 | eteindreLed(); |
marcolasek | 13:075e7b811cc6 | 73 | start = false; //Variable start à false |
marcolasek | 13:075e7b811cc6 | 74 | //lcd_.DisplayStringAt(10, Y0+120, (uint8_t *)"OFF", LEFT_MODE); //On affiche Off sur l'ecran |
marcolasek | 13:075e7b811cc6 | 75 | } |
marcolasek | 13:075e7b811cc6 | 76 | } |
MikamiUitOpen | 12:e2bb579c4455 | 77 | |
marcolasek | 13:075e7b811cc6 | 78 | lcd_.SetFont(&Font20); |
marcolasek | 13:075e7b811cc6 | 79 | if (start == true) { //Si on appuyé sur le bouton On |
marcolasek | 13:075e7b811cc6 | 80 | valeurMicro = sound.read(); //On recupere la valeur du son |
marcolasek | 13:075e7b811cc6 | 81 | sprintf(str,"Son : %f", valeurMicro); //On affiche la valeur de notre micro sur l'écran |
marcolasek | 13:075e7b811cc6 | 82 | if (valeurMicro < 0.25) { //Si on est inférieur à valeur on est inferieur à la limite on change la couleur 2 |
marcolasek | 13:075e7b811cc6 | 83 | if (mode == 1) { //Si nous somme dans le mode 1 |
marcolasek | 13:075e7b811cc6 | 84 | allumeLed(couleur1); |
marcolasek | 13:075e7b811cc6 | 85 | } else { //Sinon |
marcolasek | 13:075e7b811cc6 | 86 | allumeLed(couleur1, i); |
marcolasek | 13:075e7b811cc6 | 87 | } |
marcolasek | 13:075e7b811cc6 | 88 | } else { //Si on est supérieur à valeur on est inferieur à la limite on change la couleur 2 |
marcolasek | 13:075e7b811cc6 | 89 | if (mode == 1) { //Si nous somme dans le mode 1 |
marcolasek | 13:075e7b811cc6 | 90 | allumeLed(couleur2); |
marcolasek | 13:075e7b811cc6 | 91 | } else { //Sinon |
marcolasek | 13:075e7b811cc6 | 92 | allumeLed(couleur2, i); |
marcolasek | 13:075e7b811cc6 | 93 | } |
marcolasek | 13:075e7b811cc6 | 94 | } |
marcolasek | 13:075e7b811cc6 | 95 | } |
marcolasek | 13:075e7b811cc6 | 96 | |
marcolasek | 13:075e7b811cc6 | 97 | lcd_.DisplayStringAt(10, Y0+20, (uint8_t *)str, LEFT_MODE); //On met à jour l'affichage |
marcolasek | 13:075e7b811cc6 | 98 | bool touched = bGroup.GetTouchedNumber(num, LCD_COLOR_DARKBLUE); |
marcolasek | 13:075e7b811cc6 | 99 | if (touched) { |
marcolasek | 13:075e7b811cc6 | 100 | char str[20]; |
marcolasek | 13:075e7b811cc6 | 101 | if (num == 0) { |
marcolasek | 13:075e7b811cc6 | 102 | mode = 1; |
marcolasek | 13:075e7b811cc6 | 103 | } else { |
marcolasek | 13:075e7b811cc6 | 104 | mode =2 ; |
marcolasek | 13:075e7b811cc6 | 105 | } |
marcolasek | 13:075e7b811cc6 | 106 | |
marcolasek | 13:075e7b811cc6 | 107 | } |
marcolasek | 13:075e7b811cc6 | 108 | |
marcolasek | 13:075e7b811cc6 | 109 | wait(0.03f); //Tempo |
MikamiUitOpen | 0:35af280527cf | 110 | } |
MikamiUitOpen | 0:35af280527cf | 111 | } |
marcolasek | 13:075e7b811cc6 | 112 | |
MikamiUitOpen | 0:35af280527cf | 113 | } |
MikamiUitOpen | 12:e2bb579c4455 | 114 | |
marcolasek | 13:075e7b811cc6 | 115 | void allumeLed(long couleur) |
marcolasek | 13:075e7b811cc6 | 116 | { |
marcolasek | 13:075e7b811cc6 | 117 | Pixel strip1[N]; |
marcolasek | 13:075e7b811cc6 | 118 | strip.global_scale = lum; |
marcolasek | 13:075e7b811cc6 | 119 | for(int i =0; i <N; i++) { |
marcolasek | 13:075e7b811cc6 | 120 | strip1[i].hex = couleur; |
marcolasek | 13:075e7b811cc6 | 121 | } |
marcolasek | 13:075e7b811cc6 | 122 | strip.send(strip1, N); |
marcolasek | 13:075e7b811cc6 | 123 | } |
marcolasek | 13:075e7b811cc6 | 124 | |
marcolasek | 13:075e7b811cc6 | 125 | void allumeLed(long couleur, int i) |
marcolasek | 13:075e7b811cc6 | 126 | { |
marcolasek | 13:075e7b811cc6 | 127 | Pixel strip1[N]; |
marcolasek | 13:075e7b811cc6 | 128 | strip.global_scale = lum; |
marcolasek | 13:075e7b811cc6 | 129 | strip1[i].hex = couleur; |
marcolasek | 13:075e7b811cc6 | 130 | strip.send(strip1, i); |
marcolasek | 13:075e7b811cc6 | 131 | |
marcolasek | 13:075e7b811cc6 | 132 | } |
marcolasek | 13:075e7b811cc6 | 133 | |
marcolasek | 13:075e7b811cc6 | 134 | void eteindreLed() |
marcolasek | 13:075e7b811cc6 | 135 | { |
marcolasek | 13:075e7b811cc6 | 136 | |
marcolasek | 13:075e7b811cc6 | 137 | Pixel strip1[N]; |
marcolasek | 13:075e7b811cc6 | 138 | for(int i =0; i < N; i++) { |
marcolasek | 13:075e7b811cc6 | 139 | strip1[i].hex = 0x000000; |
marcolasek | 13:075e7b811cc6 | 140 | } |
marcolasek | 13:075e7b811cc6 | 141 | strip.global_scale = 0.01; |
marcolasek | 13:075e7b811cc6 | 142 | strip.send(strip1, N); |
marcolasek | 13:075e7b811cc6 | 143 | } |