A base d'un MPR121
https://learn.adafruit.com/adafruit-mpr121-12-key-capacitive-touch-sensor-breakout-tutorial/wiring
et d'un NeoPixel Digital RGB LED Strip - Black 30
https://www.adafruit.com/products/1460
Code source
/********************************************************* 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" #include <Adafruit_NeoPixel.h> #ifdef __AVR__ #include <avr/power.h> #endif #define LEDSPIN 5 // How many NeoPixels are attached to the Arduino? #define NUMPIXELS 30 // Parameter 1 = number of pixels in strip // Parameter 2 = Arduino pin number (most are valid) // Parameter 3 = pixel type flags, add together as needed: // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, LEDSPIN, NEO_GRB + NEO_KHZ800); // 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; int maxlasttouched = 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!"); // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket #if defined (__AVR_ATtiny85__) if (F_CPU == 16000000) clock_prescale_set(clock_div_1); #endif // End of trinket special code strip.begin(); strip.show(); // Initialize all pixels to 'off' } 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"); strip.setPixelColor(i, strip.Color(150,150,150)); // Moderately bright green color. maxlasttouched = i; } // if it *was* touched and now *isnt*, alert! if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) { Serial.print(i); Serial.println(" released"); //strip.setPixelColor(i, strip.Color(0,0,0)); // Moderately bright green color. } } int max = map(maxlasttouched,0,11,0,NUMPIXELS); int variation = map(maxlasttouched,0,11,0,255); for(int i=0;i<NUMPIXELS;i++){ if(max>0){ if(i%2 != 0 || maxlasttouched > 6){ strip.setPixelColor(i, strip.Color(variation,variation,variation)); }else{ strip.setPixelColor(i, strip.Color(0,0,0)); } }else{ strip.setPixelColor(i, strip.Color(0,0,0)); } } strip.show(); // This sends the updated pixel color to the hardware. // reset our state lasttouched = currtouched; }