Paso 4: código
// *** Initializing the Spectrum Shield pins and the reading the frequency from SparkFun *** \\
https://Learn.Sparkfun.com/tutorials/Spectrum-Shi...
Marca
#define STROBE 4
#define RESET 6
#define DC_One A0
#define DC_Two A1
#define LED_LIGHT_TREBLE 9
#define LED_LIGHT_MID 8
#define LED_LIGHT_BASS 7
int [] LEDLights = {7,8,9};
int frequenciesOne [7];
int frequenciesTwo [7];
void setup() {}
Serial.Begin(9600);
pinMode (luz estroboscópica, salida);
pinMode (RESET, salida);
pinMode (DC_One, entrada);
pinMode (DC_Two, entrada);
digitalWrite (intermitente, alta);
digitalWrite (RESET, alto);
pinMode (LED_LIGHT_TREBLE, salida);
pinMode (LED_LIGHT_MID, salida);
pinMode (LED_LIGHT_BASS, salida);
digitalWrite (intermitente, baja); Delay(1);
digitalWrite (RESET, alto); Delay(1);
digitalWrite (intermitente, alta); Delay(1);
digitalWrite (intermitente, baja); Delay(1);
digitalWrite (RESET, LOW);
}
Esta función hará que el LED débil una vez que el paralaje sonido impacto Sensor envía una 1 señal y luego volver a su brillo de //original.
void loop() {}
Read_Frequencies();
Graph_Frequencies();
Delay(50);
}
/ *** Tire de frecuencias de espectro protector *** /
void Read_Frequencies() {}
Leer las frecuencias para cada banda
para (int freqAmp = 0; freqAmp < 7; freqAmp ++) {}
frequenciesOne [freqAmp] = analogRead(DC_One);
frequenciesTwo [freqAmp] = analogRead(DC_Two);
digitalWrite (intermitente, alta);
digitalWrite (intermitente, baja);
}
}
void Graph_Frequencies() {}
int theDelay = 20;
int bassThreshold = 150;
int midThreshold = 200;
int trebleThreshold = 200;
para (int i = 0; i < 7; i ++) {}
Si (i == 0) {}
Si (frequenciesTwo [i] > bassThreshold) {}
digitalWrite (LEDLights [0], alto);
} else if (frequenciesOne [i] > bassThreshold) {}
digitalWrite (LEDLights [0], alto);
} else {}
digitalWrite (LEDLights [0], LOW);
}
Delay(theDelay);
digitalWrite (LEDLights [0], LOW);
}
Si (i == 3) {}
Si (frequenciesTwo [i] > midThreshold) {}
digitalWrite (LEDLights [1], alto);
} else if (frequenciesOne [i] > midThreshold) {}
digitalWrite (LEDLights [1], alto);
} else {}
digitalWrite (LEDLights [1], LOW);
}
Delay(theDelay);
digitalWrite (LEDLights [1], LOW);
}
Si (i == 6) {}
Si (frequenciesTwo [i] > trebleThreshold) {}
digitalWrite (LEDLights [2], alto);
} else if (frequenciesOne [i] > trebleThreshold) {}
digitalWrite (LEDLights [2], alto);
} else {}
digitalWrite (LEDLights [2], LOW);
}
Delay(theDelay);
digitalWrite (LEDLights [2], LOW);
}
}
}