Concevoir et construire un panneau d’éclairage PCB à base de PCB tactile pour contrôler la bande LED Neopixel

Touch Capacitive Based PCB Light Panel

Copier de code

#include 
#include
#include
#define PIN 10 //Neo pixel connected to pin 10
#define BUZZER 13 //BUZZER is connected to pin D13
#define N_PIXELS 23 //48 neopixel in led strip
#define MIC A5 // Microphone is connected at pin A5
#define N 10 // Number of samples
#define fadeDelay 25 // fade amount
#define noiseLevel 25 // Amount of noice we want to chop off
int ref1,ref2,ref3, ref4,ref5;       //reference values to remove offset fro using analog pins are capacitive touch
char pvs_slider_pos = 0;
char pvs_ring_pos = 0;
int samples[N]; // storage for a sample  
int periodFactor = 0; // For period calculation
int t1 = -1;  
int T;
int slope;
byte periodChanged = 0;
int Brightness=0;
int led_position=0;
CapacitiveSensor   Mode_Pad = CapacitiveSensor(9,8);
CapacitiveSensor   RGB_Pad = CapacitiveSensor(9,7);
CapacitiveSensor   Music_Pad = CapacitiveSensor(9,6);
CapacitiveSensor   Ring_L_Pad = CapacitiveSensor(9,5);
CapacitiveSensor   Ring_LT_Pad = CapacitiveSensor(9,4);
CapacitiveSensor   Ring_T_Pad = CapacitiveSensor(9,3);
CapacitiveSensor   Ring_TR_Pad = CapacitiveSensor(9,2);
//create a NeoPixel strip
Adafruit_NeoPixel strip = Adafruit_NeoPixel(N_PIXELS, PIN, NEO_GRB + NEO_KHZ800);
boolean ModeMode(){
    long Mode_Pad_Value =  Mode_Pad.capacitiveSensor(30);
    if (Mode_Pad_Value>500)
    return 1;
    else
    return 0;
}
boolean RGBMode(){
    long RGB_Pad_Value =  RGB_Pad.capacitiveSensor(30);
    if (RGB_Pad_Value>500)
    return 1;
    else
    return 0;
}
boolean MusicMode(){
    long Music_Pad_Value =  Music_Pad.capacitiveSensor(30);
    if (Music_Pad_Value>500)
    return 1;
    else
    return 0;
}
char Check_Ring_Pos()
{
    char ring_pos = 0;
    char result = 0;
    long Ring_L_Pad_Value =  Ring_L_Pad.capacitiveSensor(30);
    long Ring_LT_Pad_Value =  Ring_LT_Pad.capacitiveSensor(30);
    long Ring_T_Pad_Value =  Ring_T_Pad.capacitiveSensor(30);
    long Ring_TR_Pad_Value =  Ring_TR_Pad.capacitiveSensor(30);
    if (Ring_L_Pad_Value>500)
    ring_pos = 1;
    if (Ring_LT_Pad_Value>500)
    ring_pos = 2;
    if (Ring_T_Pad_Value>500)
    ring_pos = 3;
    if (Ring_TR_Pad_Value>500)
    ring_pos = 4;
  char current_ring_pos = ring_pos;
  Serial.println(current_ring_pos - pvs_ring_pos);
  if ((current_ring_pos - pvs_ring_pos) == 1)
  result = 1; //Serial.print("Ring touched clockwise");
  if ((current_ring_pos - pvs_ring_pos) == -1)
  result =2; //Serial.print("Ring touched counter clockwise");
  if (current_ring_pos != pvs_ring_pos);
  pvs_ring_pos = current_ring_pos;
  return result;
}
char Check_Slider_Pos()
{
    char slider_pos = 0;
    char result = 0;
    int sensorValue1 = ADCTouch.read(A0);   
    int sensorValue2 = ADCTouch.read(A1);    
    int sensorValue3 = ADCTouch.read(A2);   
    int sensorValue4 = ADCTouch.read(A3);
    int sensorValue5 = ADCTouch.read(A4);   
    sensorValue1 -= ref1;       
    sensorValue2 -= ref2;
    sensorValue3 -= ref3;       
    sensorValue4 -= ref4;
    sensorValue5 -= ref5;
    if (sensorValue1>50)
    slider_pos="1";
    if (sensorValue2>50)
    slider_pos="2";
    if (sensorValue3>50)
    slider_pos="3";
    if (sensorValue4>50)
    slider_pos="4";
    if (sensorValue5>50)
    slider_pos="5";
  char current_slider_pos = slider_pos;
  if ((current_slider_pos - pvs_slider_pos) == 1)
  result = 1; //Serial.print("Slider Left to Right");
  if ((current_slider_pos - pvs_slider_pos) == -1)
  result =2; //Serial.print("Slider Right to Left");
  if (current_slider_pos != pvs_slider_pos);
  pvs_slider_pos = current_slider_pos;
  return result;
}
void RGB_Mode(){
  Serial.print("We have entered RGB Mode");
  beep();
  uint16_t i, j, k;
  Brightness = 255;
  while(1){ //Stay in RGB mode
  char Sider_Status = Check_Slider_Pos();
  char Ring_Status = Check_Ring_Pos();
  if (Sider_Status ==1){ //return 0 for no movement and 2 for right to left
  Serial.println ("Moved Left to Right");
  beep();
  Brightness = Brightness+50;
  Serial.print(Brightness);
  }
  if (Sider_Status==2){ //return 0 for no movement and 2 for right to left
  Serial.println ("Moved Right to Left");
  beep();
  Brightness = Brightness-50;
  Serial.print(Brightness);
   }
  if (Ring_Status==1) {//return 0 for no movement and 2 for counter clockwise
  Serial.println ("Ring in Clockwise");
  beep();
  i = random (0,255);
  j = random (0,255);
  k= random (0,255);
  }
  if (Ring_Status==2) {//return 0 for no movement and 2 for counter clockwise
  Serial.println ("Ring in Counter-Clockwise");
  beep();
  i = random (0,255);
  j = random (0,255);
  k= random (0,255);
  }
  for(int x=0; x             strip.setBrightness(Brightness);
            strip.setPixelColor(x, strip.Color(i,j,k));
            strip.show();
          }  
  if ( RGBMode() || ModeMode() || MusicMode())
  break;
  }
}
void Mode_Mode(){
  Serial.print("We have entered MODE Mode");
  beep();
  while(1){ //Stay in RGB mode
  char Ring_Status = Check_Ring_Pos();
  if (Ring_Status==1) {//return 0 for no movement and 2 for counter clockwise
  Serial.println ("Ring in Clockwise");
  beep();
  }
    for(int i=0; i< 48; i++) {
     strip.setBrightness(255);
     strip.fill(255,(i+0),(1+i));
     strip.fill(0,0,i);
     strip.show();
     delay(20);
  }
  if (Ring_Status==2){ //return 0 for no movement and 2 for counter clockwise
  Serial.println ("Ring in Anti- Clockwise");
  beep();
  for(int i=48; i>0; i--) {
     strip.setBrightness(255);
     strip.fill(255,(i+0),(1+i));
     strip.fill(0,0,i);
     strip.show();
     delay(20);
  }
  }
  if ( RGBMode() || ModeMode() || MusicMode())
  break;
  }
}
void Music_Mode(){
  Serial.print("We have entered MUSIC Mode");
  beep();
  while(1){ //Stay in RGB mode
  if (digitalRead(A5)==LOW)
  {
    Serial.print("TAP");
      for(int i=0; i< 48; i++)
  {
     strip.setBrightness(random (100,255));
     strip.setPixelColor(i, strip.Color(random (0,255), random (0,255), random (0,255)));
     strip.show();
  }
  delay(100);
  }
  else
  {
  for(int i=0; i< 48; i++)
  {
     strip.setBrightness(0);
     strip.setPixelColor(i, strip.Color(random (0,255), random (0,255), random (0,255)));
     strip.show();
  }
  }
  if ( RGBMode() || ModeMode() || MusicMode() )
  break;
  }
}
void setup() {
  // start the strip and blank it out
  strip.begin();
  //strip.show();
  //cs_4_2.set_CS_AutocaL_Millis(0xFFFFFFFF);     // turn off autocalibrate on channel 1 - just as an example
   Serial.begin(9600);
   ref1 = ADCTouch.read(A0, 500);    
   ref2 = ADCTouch.read(A1, 500);     
   ref3 = ADCTouch.read(A2, 500);    
   ref4 = ADCTouch.read(A3, 500);
   ref5 = ADCTouch.read(A4, 500);
   pinMode(BUZZER, OUTPUT);
}
void loop() {
  //strip.clear();
 strip.show();
    if (ModeMode()==1)
    Mode_Mode();
    if (RGBMode()==1)
    RGB_Mode();
    if (MusicMode()==1)
    Music_Mode();
}
void beep(){
tone(BUZZER,400);
delay(50);
noTone(BUZZER);
}

Retrouvez l’histoire de Raspberry Pi dans cette vidéo :

YouTube video

  • SEZO WS2812B ECO 5M 300LED DC5V Ruban LED Adressable Individuellement SMD5050 RVB 300 Pixels Couleur de Rêve Programmable Neopixel Bande Lumineuse LED Flexible IP30 Non étanche PCB Blanc
  • Ptdfjspt Bricolage RVB Smart LED Pixel Panneau Lampe 32x 32 USB Graffiti Bluetooth App Contrôle pour la Décoration de Écran de Texte Affichage de Voiture