Il y aura cependant deux ajouts nécessaire. De quoi émettre du son. Un piezo-buzzer ou un haut-parleur placé entre la pin 9 et GND de l’Arduino. Et un code permettant de générer un son, pour celà nous utiliserons la fonction tone() et noTone().
EDIT: Et pour faire beaucoup de bruit, j’ai ajouter un petit ampli PAM8403 au montage. TUTORIEL DU PAM8403 ICI
Branchements
Pour commencer, cablez le même “schéma” que dans le précédent article et ajouter des touches a votre clavier. Voilà comment j’ai procédé:
Etape 1 – Souder les pins
Etape 2 – Passer des gaines thermorétractables
Ensuite a l’aide de papier collant double-face et d’aluminium, j’ai élargi la zone de surface:
et je les ais enfin disposé sur une feuille:
Code Arduino
Coté code on reprend le même code que dans l’article précédent:
/*********************************************************
This is a library for the MPR121 12-channel Capacitive touch sensor
Designed specifically to work with the MPR121 Breakout in the Adafruit shop
----> https://www.adafruit.com/products/
These sensors use I2C communicate, at least 2 pins are required
to interface
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
**********************************************************/
#include <Wire.h>
#include "Adafruit_MPR121.h"
// You can have up to 4 on one i2c bus but one is enough for testing!
Adafruit_MPR121 cap = Adafruit_MPR121();
// Keeps track of the last pins touched
// so we know when buttons are 'released'
uint16_t lasttouched = 0;
uint16_t currtouched = 0;
void setup() {
while (!Serial); // needed to keep leonardo/micro from starting too fast!
Serial.begin(9600);
Serial.println("Adafruit MPR121 Capacitive Touch sensor test");
// Default address is 0x5A, if tied to 3.3V its 0x5B
// If tied to SDA its 0x5C and if SCL then 0x5D
if (!cap.begin(0x5A)) {
Serial.println("MPR121 not found, check wiring?");
while (1);
}
Serial.println("MPR121 found!");
}
void loop() {
// Get the currently touched pads
currtouched = cap.touched();
for (uint8_t i=0; i<12; i++) {
// it if *is* touched and *wasnt* touched before, alert!
if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
Serial.print(i); Serial.println(" touched");tone(9,i*1000);
}
// if it *was* touched and now *isnt*, alert!
if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {
Serial.print(i); Serial.println(" released");noTone(9);
}
}
// reset our state
lasttouched = currtouched;
// comment out this line for detailed data from the sensor!
return;
// debugging info, what
Serial.print("\t\t\t\t\t\t\t\t\t\t\t\t\t 0x"); Serial.println(cap.touched(), HEX);
Serial.print("Filt: ");
for (uint8_t i=0; i<12; i++) {
Serial.print(cap.filteredData(i)); Serial.print("\t");
}
Serial.println();
Serial.print("Base: ");
for (uint8_t i=0; i<12; i++) {
Serial.print(cap.baselineData(i)); Serial.print("\t");
}
Serial.println();
// put a delay so it isn't overwhelming
delay(100);
}
La modification faite se trouve dans le void loop().
Super les tutos il sont clairs et très bien expliqué, continuez comme ça 😉
Oh merci Loic 🙂 Quelques composants qui arrivent et je m’y remet promis ^^