Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Adafruit_NeoPixel.h>
- #include <avr/power.h>
- #define PIN 6
- int analogPin = 0; // read from multiplexer using analog input 0
- int strobePin = 2; // strobe is attached to digital pin 2
- int resetPin = 3; // reset is attached to digital pin 3
- int spectrumValue[7]; // to hold a2d values
- int lightValue[5]; // resized array
- Adafruit_NeoPixel strip = Adafruit_NeoPixel(64, PIN, NEO_GRB + NEO_KHZ800);
- void setup()
- {
- Serial.begin(9600);
- pinMode(analogPin, INPUT);
- pinMode(strobePin, OUTPUT);
- pinMode(resetPin, OUTPUT);
- analogReference(DEFAULT);
- digitalWrite(resetPin, LOW);
- digitalWrite(strobePin, HIGH);
- Serial.println("MSGEQ7 test by J Skoba");
- strip.begin();
- strip.show(); // Initialize all pixels to 'off'
- }
- void loop()
- {
- int ledValue, grnVal, redVal, tmpVal, intensity;
- uint32_t c;
- digitalWrite(resetPin, HIGH);
- digitalWrite(resetPin, LOW);
- for (int i = 0; i < 7; i++){
- digitalWrite(strobePin, LOW);
- delayMicroseconds(30); // to allow the output to settle
- spectrumValue[i] = analogRead(analogPin);
- Serial.print("\t");
- Serial.print(spectrumValue[i]);
- digitalWrite(strobePin, HIGH);
- } // for i
- Serial.println();
- // Update LEDs
- for(int i=0;i<7;i++){
- if(spectrumValue[i] > 127){
- tmpVal = spectrumValue[i];
- } else{
- tmpVal = 0;
- }
- ledValue = map(tmpVal, 0, 1023-50, 0, 255);
- intensity = map(tmpVal, 0, 1023-50, 0, 7);
- c = Wheel(ledValue); //strip.Color(0,0,Wheel(ledValue) );
- for(int j=0;j<8;j++){
- if( j<intensity){
- strip.setPixelColor(j+(8*i), c );
- } else{
- strip.setPixelColor(j+(8*i), strip.Color(0,0,0) );
- }
- } // for j
- }
- strip.show();
- delay(50); // helps smooth the update flicker a bit
- }
- // Input a value 0 to 255 to get a color value.
- // The colours are a transition r - g - b - back to r.
- uint32_t Wheel(byte WheelPos) {
- WheelPos = 255 - WheelPos;
- if(WheelPos < 85) {
- /* 1
- return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
- */
- WheelPos -= 170;
- return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
- } else if(WheelPos < 170) {
- /* 2
- WheelPos -= 85;
- return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
- */
- return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
- } else {
- /* 3
- WheelPos -= 170;
- return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
- */
- WheelPos -= 85;
- return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement