Vous êtes sur la page 1sur 3

<html><head></head><body><pre style="word-wrap: break-word; white-space: pre-

wrap;">#include "FastLED.h"

FASTLED_USING_NAMESPACE

//const int DATA_PIN = 3;


#define DATA_PIN 3 // This is the Teensy pin we will use to communicate with the
LED strip
#define LED_TYPE WS2811 // This tells FastLED which driver our LED strip (NeoPixel)
uses
#define COLOR_ORDER GRB // Different drivers can have the LEDs in different orders
#define NUM_LEDS 10 // We are controlling 10 LEDs on this strip
CRGB leds[NUM_LEDS]; // creates an array to store the color values for each LED
#define BRIGHTNESS 80 // !!!!! Don't go over 80 if powering from USB !!!! (from
microcontroller)
// At brightness of 80 with all LEDs on (White) current =
115 mA
// Max is 255, but should only be used if powering LEDs
directly
// with a sufficent external power supply.

void setup() {
// tell FastLED about the LED strip configuration (uses the parameters we defined above)
FastLED.addLeds&lt;LED_TYPE, DATA_PIN, COLOR_ORDER&gt;(leds, NUM_LEDS); // GBR with Max
data???

FastLED.setBrightness(BRIGHTNESS); // set master brightness control

Serial.begin(9600); // Initialize serial communications


}

void loop() {
int sensorValue = analogRead(A0); //Takes a reading from the potentiometer
Serial.println(sensorValue);

if (sensorValue&lt;150) // Turns all of the LED's off, when analog


value is less than 150
{
leds[0] = CRGB(0, 0, 0);
leds[1] = CRGB(0, 0, 0);
leds[2] = CRGB(0, 0, 0);
leds[3] = CRGB(0, 0, 0);
leds[4] = CRGB(0, 0, 0);
leds[5] = CRGB(0, 0, 0);
leds[6] = CRGB(0, 0, 0);
leds[7] = CRGB(0, 0, 0);
leds[8] = CRGB(0, 0, 0);
leds[9] = CRGB(0, 0, 0);
}
if (sensorValue&gt;150 &amp;&amp; sensorValue&lt;400) // Turns half the LED's to one
color, and the other half to another color. when analog value is more than 150 and less
than 400
{
leds[0] = CRGB(255, 0, 0);
leds[1] = CRGB(255, 0, 0);
leds[2] = CRGB(255, 0, 0);
leds[3] = CRGB(255, 0, 0);
leds[4] = CRGB(255, 0, 0);
leds[5] = CRGB(0, 0, 255);
leds[6] = CRGB(0, 0, 255);
leds[7] = CRGB(0, 0, 255);
leds[8] = CRGB(0, 0, 255);
leds[9] = CRGB(0, 0, 255);
}
if (sensorValue&gt;400 &amp;&amp; sensorValue&lt;650) // Turns half the LED's to one
color, and the other half to another color. when the analog value is more than 400 and
less than 650
{
leds[0] = CRGB(0, 255, 0);
leds[1] = CRGB(0, 255, 0);
leds[2] = CRGB(0, 255, 0);
leds[3] = CRGB(0, 255, 0);
leds[4] = CRGB(0, 255, 0);
leds[5] = CRGB(255, 0, 255);
leds[6] = CRGB(255, 0, 255);
leds[7] = CRGB(255, 0, 255);
leds[8] = CRGB(255, 0, 255);
leds[9] = CRGB(255, 0, 255);
}
if (sensorValue&gt;650 &amp;&amp; sensorValue&lt;900) // Turns half the LED's to one
color, and the other half to another color. when the alanog value is more than 650 and
less than 900.
{
leds[0] = CRGB(255, 255, 0);
leds[1] = CRGB(255, 255, 0);
leds[2] = CRGB(255, 255, 0);
leds[3] = CRGB(255, 255, 0);
leds[4] = CRGB(255, 255, 0);
leds[5] = CRGB(0, 255, 255);
leds[6] = CRGB(0, 255, 255);
leds[7] = CRGB(0, 255, 255);
leds[8] = CRGB(0, 255, 255);
leds[9] = CRGB(0, 255, 255);
}
if (sensorValue&gt;900) //Turns all the LED's to white, when the analog
value is more than 900
{
leds[0] = CRGB(255, 255, 255);
leds[1] = CRGB(255, 255, 255);
leds[2] = CRGB(255, 255, 255);
leds[3] = CRGB(255, 255, 255);
leds[4] = CRGB(255, 255, 255);
leds[5] = CRGB(255, 255, 255);
leds[6] = CRGB(255, 255, 255);
leds[7] = CRGB(255, 255, 255);
leds[8] = CRGB(255, 255, 255);
leds[9] = CRGB(255, 255, 255);
}

FastLED.show(); // Set the LEDs to the specified color and brightness

}
</pre></body></html>

Vous aimerez peut-être aussi