#include #define LED_PIN 0 #define NUM_LEDS 140 int frequency = 0; CRGB leds[NUM_LEDS]; //int frequency , amp; void setup() { Serial.begin(9600); FastLED.addLeds(leds, NUM_LEDS); } /* for (int i = 2; i < (SAMPLES/2); i++){ // Don't use sample 0 and only first SAMPLES/2 are usable. Each array element represents a frequency bin and its value the amplitude. if (i>0 && i<=5 ) bandValues[1] += (int)vReal[i]; if (i>5 && i<=10 ) bandValues[2] += (int)vReal[i]; if (i>10 && i<=15 ) bandValues[3] += (int)vReal[i]; if (i>15 && i<=20 ) bandValues[4] += (int)vReal[i]; } int barHeight = 35; for (byte band = 0; band < NUM_BANDS; band++) { // Scale the bars for the display int barHeight = bandValues[band] / AMPLITUDE; if (barHeight > TOP) barHeight = TOP; // Small amount of averaging between frames barHeight = ((oldBarHeights[band] * 1) + barHeight) / 2; // Move peak up if (barHeight > peak[band]) { peak[band] = min(TOP, barHeight); } int barHeight = 35; for (byte band = 0; band < NUM_BANDS; band++) { // Scale the bars for the display int barHeight = bandValues[band] / AMPLITUDE; if (barHeight > TOP) barHeight = TOP; // Small amount of averaging between frames barHeight = ((oldBarHeights[band] * 1) + barHeight) / 2; // Move peak up if (barHeight > peak[band]) { peak[band] = min(TOP, barHeight); } */ void loop() { if (Serial.available() > 0) { // read the incoming byte: frequency = Serial.read(); // say what you got: Serial.print("I received: "); Serial.println(frequency, DEC); } for (int i = 0; i <= 140; i++) { leds[i] = CRGB ( 0, 0, 255); FastLED.show(); delay(40); } if (frequency>0 && frequency<=5 ) { for (int i = 0; i <= 35; i++) { leds[i] = CRGB ( 0, 0, 255); FastLED.show(); delay(40); } } if (frequency>5 && frequency<=10 ) { for (int i = 0; i <= 35; i++) { leds[i] = CRGB ( 0, 0, 255); FastLED.show(); delay(40); } for (int i = 35; i <= 70; i++) { leds[i] = CRGB ( 0, 0, 255); FastLED.show(); delay(40); } } if (frequency>10 && frequency<=15 ) { for (int i = 0; i <= 35; i++) { leds[i] = CRGB ( 0, 0, 255); FastLED.show(); delay(40); } for (int i = 35; i <= 70; i++) { leds[i] = CRGB ( 0, 0, 255); FastLED.show(); delay(40); } for (int i = 70; i <= 105; i++) { leds[i] = CRGB ( 0, 0, 255); FastLED.show(); delay(40); } } if (frequency >= 25 ) { for (int i = 0; i <= 35; i++) { leds[i] = CRGB ( 0, 0, 255); FastLED.show(); delay(40); } for (int i = 35; i <= 70; i++) { leds[i] = CRGB ( 0, 0, 255); FastLED.show(); delay(40); } for (int i = 70; i <= 105; i++) { leds[i] = CRGB ( 0, 0, 255); FastLED.show(); delay(40); } for (int i = 105; i <= 140; i++) { leds[i] = CRGB ( 0, 0, 255); FastLED.show(); delay(40); } } }