看到这样一个效果,于是想用arduino实现类似效果。需要的组件如下
1 arduino开发板
2 音频传感器
3 灯带
接线图如图
代码如下
#include <EEPROM.h>
#include <Adafruit_NeoPixel.h>
#define PIN 2 // input pin Neopixel is attached to
#define NUMPIXELS 10 // number of neopixels in strip
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
int delayval = 1; // timing delay in milliseconds
int redColor = 0;
int greenColor = 0;
int blueColor = 0;
void setup() {
pixels.begin();
Serial.begin(9600);
}
void loop() {
int val=analogRead(A1);
Serial.println(map(val,0,1023,1,10));
show(map(val,0,1023,1,10));
//del