// 先用Arduino做 ,之後再找晶片
// https://item.jd.com/24364670781.html
//https://www.banggood.com/With-Housing-DIY-Music-Spectrum-LED-Flash-Kit-DIY-Amplifier-Speaker-Kit-p-986043.html?utm_source=youtube&utm_medium=CreativeChannel&utm_campaign=Nov&utm_content=huangwenjie&cur_warehouse=CN
const byte potPin = A0;
const byte pins[6] = {D3, D2, D4, D5, D6, D0 };
int val;
int k;
void setup() {
Serial.begin(9600);
pinMode(D0, OUTPUT);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
pinMode(D5, OUTPUT);
pinMode(D6, OUTPUT);
for (int thisPin = 0; thisPin < 6; thisPin++) {
pinMode(pins[thisPin], OUTPUT); }
}
void loop() {
val = analogRead(potPin);
Serial.print("val=");
Serial.println(val);
k = val/147; // 1024/7 = 147
Serial.print("val/147=");
Serial.println(k);
for (int thisPin = 0; thisPin < k; thisPin++) {
digitalWrite(pins[thisPin], HIGH); }
delay (100);
for (int thisPin = 0; thisPin < k; thisPin++) {
digitalWrite(pins[thisPin], LOW); }
}
沒有留言:
張貼留言