Skip to content

Instantly share code, notes, and snippets.

@BarrYPL
Created April 7, 2018 09:52
Show Gist options
  • Save BarrYPL/4a7f67d541e153f46802610be0ef0abb to your computer and use it in GitHub Desktop.
Save BarrYPL/4a7f67d541e153f46802610be0ef0abb to your computer and use it in GitHub Desktop.
#include <FastLED.h>
#define NUM_LEDS 8
#define LED_PIN 6
#define LED_TYPE WS2812
#define COLOR_ORDER GRB
#define ANALOG_READ 0
CRGB led[NUM_LEDS];
#define BRIGHTNESS 28
#define FRAMES_PER_SECOND 120
int sensorPin = A0;
int sensorValue = 0;
int vum = 0;
int measur = 0;
void setup() {
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(led, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
Serial.begin (28800);
}
void AllWhite() {
for (int i = 0; i < NUM_LEDS; i++) {
led[i] = CRGB(255, 255, 255);
}
FastLED.show();
}
void Reset() {
for (int i = 0; i < NUM_LEDS; i++) {
led[i] = CRGB(0, 0, 0);
}
FastLED.show();
}
void loop() {
for (int i = 0; i < 256; i++) {
sensorValue = analogRead (sensorPin);
measur = (sensorValue-350);
vum = ((measur * NUM_LEDS) / 765);
Serial.println(measur);
if (sensorValue < 765)
{
fill_rainbow(led, vum, i);
FastLED.show();
Reset();
}
else
{
Reset();
AllWhite();
delay(50);
Reset();
}
delay(8);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment