• Witaj na Forum Arduino Polska! Zapraszamy do rejestracji!
  • Znajdziesz tutaj wiele informacji na temat hardware / software.
Witaj! Logowanie Rejestracja


Ocena wątku:
  • 0 głosów - średnia: 0
  • 1
  • 2
  • 3
  • 4
  • 5
neopixel sterowany czujnikiem dźwięku bład
#1
witam 
Chce zrobić podświetlenie z taśmy led ws2812 która będzie zmieniała kolor po uderzeniu bassu (czujnik dźwięku znajduje się tuz obok głośnika ) a podczas ciszy wyłączała się lub włączał się zadany kolor np czerwony .
w tym monecie kolor się zmienia bardzo dobrze ale podczas ciszy pozostaje 
siła świecenia steruje potencjometr 

przerobiny kod z przykładu neopixel

Kod:
#include <Adafruit_NeoPixel.h>

#define BUTTON_PIN   2    // Digital IO pin connected to the button.  This will be
                         // driven with a pull-up resistor so the switch should
                         // pull the pin to ground momentarily.  On a high -> low
                         // transition the button press logic will execute.

#define PIXEL_PIN    13    // Digital IO pin connected to the NeoPixels.

#define PIXEL_COUNT 5

// Parameter 1 = number of pixels in strip,  neopixel stick has 8
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_RGB     Pixels are wired for RGB bitstream
//   NEO_GRB     Pixels are wired for GRB bitstream, correct for neopixel stick
//   NEO_KHZ400  400 KHz bitstream (e.g. FLORA pixels)
//   NEO_KHZ800  800 KHz bitstream (e.g. High Density LED strip), correct for neopixel stick
Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL_COUNT, PIXEL_PIN, NEO_GRB + NEO_KHZ800);

bool oldState = HIGH;
bool stat=LOW;
int showType = 0;
int a,b,c=0;

void setup() {
 Serial.begin(9600);
 pinMode(BUTTON_PIN, INPUT_PULLUP);
 strip.begin();
 strip.show(); // Initialize all pixels to 'off'
}

void loop() {
 // Get current button state.
 bool newState = digitalRead(BUTTON_PIN);
int potencjometr = analogRead(A0)/4;
 strip.setBrightness(potencjometr) ;
 // Check if state changed from high to low (button press).
 if (newState == LOW && oldState == HIGH) {
   // Short delay to debounce button.
   delay(20);
   // Check if button is still low after debounce.
   newState = digitalRead(BUTTON_PIN);
   
   if (newState == HIGH) {
   for(int z=0; z<2; z++){
   color();
   }
   
   
   }
   
   
   if(newState == LOW){
     for(int i=0; i<strip.numPixels(); i++) {
   strip.clear();
 
   }
   strip.show();
     }
}
   
 oldState = newState;
   
   
     
 
}
 // Set the last button state to the old state.
 

void color(){
     a=random(5,255);
     b=random(5,255);
     c=random(5,255);
     
   for(int i=0; i<strip.numPixels(); i++) {
   strip.setPixelColor(i, a,b , c);
 
   }
   strip.show();
   delay(20);
 }

void brak(){
 for(int i=0; i<strip.numPixels(); i++) {
   strip.setPixelColor(i, 255,0 , 0);
   
 }
 strip.show();
}
 
Odpowiedź
  


Skocz do:


Przeglądający: 1 gości