Catégories
Liens
une carte de Marseille audio interactive, dans le cadre du projet “Expérimenter la ville - Place à l'art de la mobilité.”
déroulé :
Ce bout de code nécessite le télechargement des librairies specifiques :
#include <SoftwareSerial.h> #include <DFPlayer_Mini_Mp3.h> #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; volgen int volume_mp3 = 15; del between volume changes int del = 40; 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!");
mp3_set_serial (Serial); set Serial for DFPlayer-mini mp3 module delay(1); wait 1ms for mp3 module to set volume
mp3_set_volume (15);
}
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)) ) { // fade-out try to avoid clip stop/start (clipping anyway...) mp3_set_volume (volume_mp3 - 4); delay (del); mp3_set_volume (volume_mp3 - 7); delay (del); mp3_set_volume (volume_mp3 - 10); delay (del); mp3_set_volume (volume_mp3 - 15); delay (del); mp3_stop (); delay (del); mp3_set_volume (volume_mp3 - 10); delay (del); mp3_set_volume (volume_mp3 - 7); delay (del); mp3_set_volume (volume_mp3 - 4); delay (del); mp3_set_volume (volume_mp3); delay (del); mp3_play (i); delay (100); }
}
reset our state lasttouched = currtouched; put a delay so it isn't overwhelming
delay(100);
} </code>
Retrouvez l'ensemble des enregistrements sur la page projet du site colorClic.