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

  1.  /*********************************************************
  2.  This is a library for the MPR121 12-channel Capacitive touch sensor
  3.  
  4.  Designed specifically to work with the MPR121 Breakout in the Adafruit shop
  5.   ----> https://www.adafruit.com/products/
  6.  
  7.  These sensors use I2C communicate, at least 2 pins are required
  8.  to interface
  9.  
  10.  Adafruit invests time and resources providing this open source code,
  11.  please support Adafruit and open-source hardware by purchasing
  12.  products from Adafruit!
  13.  
  14.  Written by Limor Fried/Ladyada for Adafruit Industries.
  15.  BSD license, all text above must be included in any redistribution
  16.  **********************************************************/
  17.  
  18.  #include <Wire.h>
  19.  #include "Adafruit_MPR121.h"
  20.  #include <Adafruit_NeoPixel.h>
  21.  #ifdef __AVR__
  22.   #include <avr/power.h>
  23.  #endif
  24.  
  25.  #define LEDSPIN 5
  26.  // How many NeoPixels are attached to the Arduino?
  27.  #define NUMPIXELS 30
  28.  
  29.  // Parameter 1 = number of pixels in strip
  30.  // Parameter 2 = Arduino pin number (most are valid)
  31.  // Parameter 3 = pixel type flags, add together as needed:
  32.  // NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
  33.  // NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
  34.  // NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
  35.  // NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
  36.  Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, LEDSPIN, NEO_GRB + NEO_KHZ800);
  37.  
  38.  // You can have up to 4 on one i2c bus but one is enough for testing!
  39.  Adafruit_MPR121 cap = Adafruit_MPR121();
  40.  
  41.  // Keeps track of the last pins touched
  42.  // so we know when buttons are 'released'
  43.  uint16_t lasttouched = 0;
  44.  uint16_t currtouched = 0;
  45.  int maxlasttouched = 0 ;
  46.  
  47.  void setup() {
  48.   //while (!Serial); // needed to keep leonardo/micro from starting too fast!
  49.   Serial.begin(9600);
  50.   Serial.println("Adafruit MPR121 Capacitive Touch sensor test");
  51.  
  52.   // Default address is 0x5A, if tied to 3.3V its 0x5B
  53.   // If tied to SDA its 0x5C and if SCL then 0x5D
  54.   if (!cap.begin(0x5A)) {
  55.   Serial.println("MPR121 not found, check wiring?");
  56.   while (1);
  57.   }
  58.   Serial.println("MPR121 found!");
  59.  
  60.   // This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
  61.   #if defined (__AVR_ATtiny85__)
  62.   if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
  63.   #endif
  64.   // End of trinket special code
  65.  
  66.   strip.begin();
  67.   strip.show(); // Initialize all pixels to 'off'
  68.  }
  69.  
  70.  void loop() {
  71.   // Get the currently touched pads
  72.   currtouched = cap.touched();
  73.  
  74.  
  75.   for (uint8_t i=0; i<12; i++) {
  76.   // it if *is* touched and *wasnt* touched before, alert!
  77.   if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
  78.   Serial.print(i); Serial.println(" touched");
  79.   strip.setPixelColor(i, strip.Color(150,150,150)); // Moderately bright green color.
  80.   maxlasttouched = i;
  81.   }
  82.   // if it *was* touched and now *isnt*, alert!
  83.   if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {
  84.   Serial.print(i); Serial.println(" released");
  85.   //strip.setPixelColor(i, strip.Color(0,0,0)); // Moderately bright green color.
  86.   }
  87.   }
  88.  
  89.   int max = map(maxlasttouched,0,11,0,NUMPIXELS);
  90.   int variation = map(maxlasttouched,0,11,0,255);
  91.   for(int i=0;i<NUMPIXELS;i++){
  92.   if(max>0){
  93.   if(i%2 != 0 || maxlasttouched > 6){
  94.   strip.setPixelColor(i, strip.Color(variation,variation,variation));
  95.   }else{
  96.   strip.setPixelColor(i, strip.Color(0,0,0));
  97.   }
  98.   }else{
  99.   strip.setPixelColor(i, strip.Color(0,0,0));
  100.   }
  101.   }
  102.  
  103.   strip.show(); // This sends the updated pixel color to the hardware.
  104.   // reset our state
  105.   lasttouched = currtouched;
  106.  }