Facebook
From Whipped Sloth, 1 Year ago, written in C.
Embed
Download Paste or View Raw
Hits: 128
  1. #include <FastLED.h>
  2. #define LED_PIN     0
  3. #define NUM_LEDS    140
  4. int frequency = 0;
  5. CRGB leds[NUM_LEDS];
  6. //int frequency , amp;
  7.  
  8.  
  9.  
  10. void setup() {
  11.   Serial.begin(9600);
  12.   FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  13.  
  14. }
  15.  /*
  16.   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.
  17.      
  18.  
  19.       if (i>0   && i<=5  ) bandValues[1]  += (int)vReal[i];
  20.       if (i>5   && i<=10 ) bandValues[2]  += (int)vReal[i];
  21.       if (i>10  && i<=15 ) bandValues[3]  += (int)vReal[i];
  22.       if (i>15  && i<=20 ) bandValues[4]  += (int)vReal[i];
  23.    
  24.   }
  25.  
  26.   int barHeight = 35;
  27.  
  28.   for (byte band = 0; band < NUM_BANDS; band++) {
  29.  
  30.     // Scale the bars for the display
  31.     int barHeight = bandValues[band] / AMPLITUDE;
  32.     if (barHeight > TOP) barHeight = TOP;
  33.  
  34.     // Small amount of averaging between frames
  35.     barHeight = ((oldBarHeights[band] * 1) + barHeight) / 2;
  36.  
  37.     // Move peak up
  38.     if (barHeight > peak[band]) {
  39.       peak[band] = min(TOP, barHeight);
  40.     }
  41.   int barHeight = 35;
  42.  
  43.   for (byte band = 0; band < NUM_BANDS; band++) {
  44.  
  45.     // Scale the bars for the display
  46.     int barHeight = bandValues[band] / AMPLITUDE;
  47.     if (barHeight > TOP) barHeight = TOP;
  48.  
  49.     // Small amount of averaging between frames
  50.     barHeight = ((oldBarHeights[band] * 1) + barHeight) / 2;
  51.  
  52.     // Move peak up
  53.     if (barHeight > peak[band]) {
  54.       peak[band] = min(TOP, barHeight);
  55.     }
  56. */
  57. void loop() {
  58.  
  59.    if (Serial.available() > 0) {
  60.     // read the incoming byte:
  61.     frequency = Serial.read();
  62.  
  63.     // say what you got:
  64.     Serial.print("I received: ");
  65.     Serial.println(frequency, DEC);
  66.   }
  67.  
  68.   for (int i = 0; i <= 140; i++) {
  69.     leds[i] = CRGB ( 0, 0, 255);
  70.     FastLED.show();
  71.     delay(40);
  72.   }
  73.  
  74. if (frequency>0   && frequency<=5  )
  75. {
  76. for (int i = 0; i <= 35; i++) {
  77.     leds[i] = CRGB ( 0, 0, 255);
  78.     FastLED.show();
  79.     delay(40);
  80.  
  81. }
  82.  
  83. }
  84.  
  85. if (frequency>5   && frequency<=10  )
  86. {
  87.  
  88. for (int i = 0; i <= 35; i++) {
  89.     leds[i] = CRGB ( 0, 0, 255);
  90.     FastLED.show();
  91.     delay(40);
  92. }
  93.  
  94. for (int i = 35; i <= 70; i++) {
  95.     leds[i] = CRGB ( 0, 0, 255);
  96.     FastLED.show();
  97.     delay(40);
  98.  
  99. }
  100.  
  101. }
  102.  
  103. if (frequency>10   && frequency<=15  )
  104. {
  105.  
  106. for (int i = 0; i <= 35; i++) {
  107.     leds[i] = CRGB ( 0, 0, 255);
  108.     FastLED.show();
  109.     delay(40);
  110.  
  111. }
  112. for (int i = 35; i <= 70; i++) {
  113.     leds[i] = CRGB ( 0, 0, 255);
  114.     FastLED.show();
  115.     delay(40);
  116.  
  117. }
  118.  
  119. for (int i = 70; i <= 105; i++) {
  120.     leds[i] = CRGB ( 0, 0, 255);
  121.     FastLED.show();
  122.     delay(40);
  123.  
  124. }
  125.  
  126. }
  127.  
  128. if (frequency >= 25 )
  129. {
  130.  
  131. for (int i = 0; i <= 35; i++) {
  132.     leds[i] = CRGB ( 0, 0, 255);
  133.     FastLED.show();
  134.     delay(40);
  135.  
  136. }
  137. for (int i = 35; i <= 70; i++) {
  138.     leds[i] = CRGB ( 0, 0, 255);
  139.     FastLED.show();
  140.     delay(40);
  141.  
  142. }
  143.  
  144. for (int i = 70; i <= 105; i++) {
  145.     leds[i] = CRGB ( 0, 0, 255);
  146.     FastLED.show();
  147.     delay(40);
  148.  
  149. }
  150.  
  151. for (int i = 105; i <= 140; i++) {
  152.     leds[i] = CRGB ( 0, 0, 255);
  153.     FastLED.show();
  154.     delay(40);
  155.  
  156. }
  157.  
  158. }
  159.  
  160.  
  161. }