Paso 2: Obtener el código
También he publicado el código de abajo, pero le sugiero que visite akcarl de instructable.
//// Beat Sync// A music visualization device.// Created by// Carl Smith// penguinmagic #include <fix_fft.h> int led[] = {5,6,7,8,9,10,11,12}; int x = 0; char im[128], data[128]; char data_avgs[14]; int i=0,val; #define AUDIOPIN 3 voidsetup() { for (int i = 0; i <8; i++) { pinMode(led[i], OUTPUT); } Serial.begin(9600); } voidloop() { for (i=0; i < 128; i++){ val = analogRead(AUDIOPIN); data[i] = val; im[i] = 0; }; fix_fft(data,im,7,0); for (i=0; i< 64;i++){ data[i] = sqrt(data[i] * data[i] + im[i] * im[i]); // this gets the absolute value of the values in the //array, so we're only dealing with positive numbers }; // average bars together for (i=0; i<14; i++) { data_avgs[i] = data[i*4] + data[i*4 + 1] + data[i*4 + 2] + data[i*4 + 3]; // average together data_avgs[i] = map(data_avgs[i], 0, 30, 0, 9); // remap values for LoL } int value = data_avgs[0];//0 for bass ledArray(value); } void ledArray(int input) { // if (input > 8) { for (int i = 0; i <8; i++) { digitalWrite(led[i], HIGH); } } elseif (input > 7) { for (int i = 0; i <7; i++) { digitalWrite(led[i], HIGH); } for (int i = 7; i <8; i++) { digitalWrite(led[i], LOW); } } elseif (input > 6) { for (int i = 0; i <6; i++) { digitalWrite(led[i], HIGH); } for (int i = 6; i <8; i++) { digitalWrite(led[i], LOW); } } elseif (input > 5) { for (int i = 0; i <5; i++) { digitalWrite(led[i], HIGH); } for (int i = 5; i <8; i++) { digitalWrite(led[i], LOW); } } elseif (input > 4) { for (int i = 0; i <4; i++) { digitalWrite(led[i], HIGH); } for (int i = 4; i <8; i++) { digitalWrite(led[i], LOW); } } elseif (input > 3) { for (int i = 0; i <3; i++) { digitalWrite(led[i], HIGH); } for (int i = 3; i <8; i++) { digitalWrite(led[i], LOW); } } elseif (input > 2) { for (int i = 0; i <2; i++) { digitalWrite(led[i], HIGH); } for (int i = 2; i <8; i++) { digitalWrite(led[i], LOW); } } elseif (input > 1) { for (int i = 0; i <1; i++) { digitalWrite(led[i], HIGH); } for (int i = 1; i <8; i++) { digitalWrite(led[i], LOW); } } else { for (int i = 0; i <8; i++) { digitalWrite(led[i], LOW); } } }