/////////////////////// // DIY TouchBoard // // ESP8266 // /////////////////////// /* LOLIN (wemos)D1 mini Capteur capacitif MPR121 _______________________________ / _________________ \ _________________ / / D1 mini \ \ | L 11[ ]| / |[ ]RST TX[ ]| \ | E 10[ ]| | |[ ]A0 -GPIO RX[ ]| \ | D 9[ ]| | |[ ]D0-16 5-D1[X]| SCL----------. \-|[X]3,3V / 8[ ]| .-----|--|[X]D5-14 4-D2[X]| SDA---------. \ |[ ]IRQ e 7[ ]| / .--|--|[X]D6-12 0-D3[ ]| \ \-|[X]SCL l 6[ ]| / / | |[ ]D7-13 2-D4[ ]| LED_BUILTIN \--|[X]SDA e 5[ ]| / / | |[ ]D8-15 GND[X]|---.----------. |[ ]ADD c 4[ ]| | / \--|[X]3V3 5V[X]|\ \ \--|[X]GND t 3[ ]| | / | +---+ | | | | r 2[ ]| | | |_______|USB|_______| | | | o 1[ ]| | | | | | MPR121 d 0[ ]| | | _____________________/ | |_________e_______| Lecteur MP3 | | / | | | | +-------\_/--------+ | |\ | | 1K \--|[X] MP3-TF-16P [ ]| | | \ | \-WW-----RX|[X] DFPlayer [ ]| | | \ _ \----------TX|[X] __________ [ ]| | | | |----. |[ ]| |[ ]| | | |_|-. \ |[ ]| CARTE |[ ]| | | / \ \--Haut-Parleur |[X]| SD |[ ]| | | / \ |[ ]| |[X]|GND-/ |/ \----Haut-Parleur |[X]| |[ ]| |___|__________|___| Matériel : - Des fils dupont. - Un LOLIN (ou Wemos) D1 mini - Capteur capacitif MPR121 - Lecteur mp3 MP3-TF-16P DFPlayer - Une carte SD - Un haut-parleur Schéma de l'Arduino en ASCII-ART CC-By http://busyducks.com/ascii-art-arduinos Sous licence CC-By-Sa (http://creativecommons.org/licenses/by-nc-sa/3.0/) ___ / ___ \ |_| | /_/ _ ___ _ |_| |___|_| |_ ___|_ _| |___| |_| Les petits Débrouillards - janvier 2023- CC-By-Sa http://creativecommons.org/licenses/by-nc-sa/3.0/ */ #include #include "Adafruit_MPR121.h" #include #include SoftwareSerial maComSerie(D5, D6); // TX, RX DFRobotDFPlayerMini monLecteurMP3 ; // création du lecteur MP3 #ifndef _BV #define _BV(bit) (1 << (bit)) #endif // Vous pouvez en avoir jusqu'à 4 MPR121 sur un bus i2c mais un seul suffit pour les tests ! Adafruit_MPR121 detecteur = Adafruit_MPR121(); uint16_t precedentTouche = 0; uint16_t actuelleTouche = 0; void setup () { Serial.begin(9600); // initialisation de la communication Série pour le débbugage while (!Serial) { // indispensable pour empêcher de démarrer trop vite ! delay(10); } //--------------------Démarrage------------------ Serial.println("Démarrage de DIY Touchboard ESP8266"); delay(100); pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, LOW); // On allume la led du D1 mini. //--------------Démarrage du MPR121--------------- detecteur.begin(0x5A); // initialisation du capteur tactile MPR121, 0x5A est l'adresse par défaut du capteur delay(100); Serial.print("démmarrage du capteur MPR121 : "); while (!detecteur.begin(0x5A)) { // On patiente en attendant le démarrage delay(100); Serial.print("."); } Serial.println("MPR121 trouvé !"); //-------------Démarrage du Lecteur MP3------------- maComSerie.begin(9600) ; // Démmarrage de la communication avec le lecteur MP3 Serial.println(); Serial.println(F("Initialisation du lecter MP3 DFPlayer ... (Peut prendre 3~5 secondes)")); monLecteurMP3.begin(maComSerie); // Initialisation du lectur MP3 Serial.print("démmarrage du lecteur MP3 : "); while (!monLecteurMP3.begin(maComSerie)) { // On patiente en attendant le démarrage delay(100); Serial.print("."); } Serial.println(F("Lecteur MP3 DFPlayer Mini en ligne !")); monLecteurMP3.setTimeOut(500); // place la communication serie time out 500ms monLecteurMP3.volume(20); // règle le volume (de 0 to 30). //--------------tout s'est bien passé----------------------- digitalWrite(LED_BUILTIN, HIGH); // Tout s'est bien passé, On éteint la led du D1 mini. } void loop() { // récupère les broches touchées actuelleTouche = detecteur.touched(); for (uint8_t i=0; i<12; i++) { // Si la broche est touchée et n'était pas touchée avant if ((actuelleTouche & _BV(i)) && !(precedentTouche & _BV(i)) ) { Serial.print("Broche : "); Serial.print(i); Serial.println(" touchée"); int son = i+1; monLecteurMP3.play(son); // joue le fichier son. } // Si la broche à déjà été touchée mais n'est plus touchée (c'est à dire si la broche est relachée) if (!(actuelleTouche & _BV(i)) && (precedentTouche & _BV(i)) ) { Serial.print("Broche : "); Serial.print(i); Serial.println(" relachée"); } } // On mémorise precedentTouche = actuelleTouche; }