Paso 4: Conseguir empezar con la biblioteca de FastLED y subir el Arduino Sketch
Principalmente trabajo con la Biblioteca de FastLED.io para la programación de LED, es bastante fácil cuando se trata de programación RGB, y gran documentación para su código.
Aquí le damos un instructivo que detalla la instalación de la biblioteca de FastLED.
Este es el código que necesita para subir en el Arduino:
// // // // // // // ultimate night bike by AUDREY LOVE // a project for Arduino, Radioshack LED Tricolor Light Strip, and a bicycle. // // // // // with great support from the FastLED.io Library // download it here: https://github.com/FastLED // // // #include "FastLED.h" #define NUM_LEDS 10 #define DATA_PIN 6 CRGB leds[NUM_LEDS]; //__________pin designations int programIndicator = 13; //Pin Number for the LED program indicator int buttonPin = 2; // the number of the pushbutton pin // Variables will change: int ledState = LOW; // ledState used to set the LED long previousMillis = 0; // will store last time LED was updated long intervalOne = 1500; // interval at which to blink (milliseconds) long intervalTwo = 500; // interval at which to blink (milliseconds) long intervalThree = 300; // interval at which to blink (milliseconds) long intervalFour = 200; // interval at which to blink (milliseconds) long intervalFive = 100; // interval at which to blink (milliseconds) long intervalSix = 50; // interval at which to blink (milliseconds) int brightValue = 0; int satValue = 0; int hueValue = 0; //button boolean buttonValue = true; // variable for reading the button status boolean buttonState = true; // variable to hold the button state //pattern int patternProgram = 0; // which button program is in use void setup() { // declare signal pins pinMode(programIndicator, OUTPUT); pinMode(buttonPin,INPUT_PULLUP); // sanity check delay - allows reprogramming if accidently blowing power w/leds delay(2000); FastLED.addLeds<TM1803, DATA_PIN, GBR>(leds, NUM_LEDS); Serial.begin(9600); // initialize serial communication at 9600 bits per second: } void loop() { // Serial.println(buttonValue); Serial.println(patternProgram); // button presses cycle through modes buttonValue = !digitalRead(buttonPin); // read input value and store it in val if (buttonValue != buttonState) { // the button state has changed! if (buttonValue == 0) { // check if the button is pressed if (patternProgram == 0) { // if set to smooth logarithmic mapping patternProgram = 1; // switch to stepped chromatic mapping } else { if (patternProgram == 1) { // patternProgram = 2; // switch to next mode } else { if (patternProgram == 2) { // patternProgram = 3; // switch to next mode } else { if (patternProgram == 3) { // patternProgram = 4; //switch to next mode } else { if (patternProgram == 4) { // patternProgram = 5; //switch to next mode } else { if (patternProgram == 5) { // patternProgram = 0; // switch to next mode } } } } } } } buttonState = buttonValue; // save the new state in our variable } brightValue = analogRead(A2); satValue = analogRead(A3); hueValue = analogRead(A4); Serial.println(hueValue); switch(patternProgram){ case 0: leds[0] = CHSV((hueValue/4)+1, (satValue/4)+1, (brightValue/4)+1); leds[1] = CHSV((hueValue/4)+1, (satValue/4)+1, (brightValue/4)+1); leds[2] = CHSV((hueValue/4)+1, (satValue/4)+1, (brightValue/4)+1); leds[3] = CHSV((hueValue/4)+1, (satValue/4)+1, (brightValue/4)+1); leds[4] = CHSV((hueValue/4)+1, (satValue/4)+1, (brightValue/4)+1); leds[5] = CHSV((hueValue/4)+1, (satValue/4)+1, (brightValue/4)+1); leds[6] = CHSV((hueValue/4)+1, (satValue/4)+1, (brightValue/4)+1); leds[7] = CHSV((hueValue/4)+1, (satValue/4)+1, (brightValue/4)+1); leds[8] = CHSV((hueValue/4)+1, (satValue/4)+1, (brightValue/4)+1); leds[9] = CHSV((hueValue/4)+1, (satValue/4)+1, (brightValue/4)+1); FastLED.show(); // delay(40); break; case 1: { unsigned long currentMillis = millis(); if(currentMillis - previousMillis > intervalTwo) { // save the last time you blinked the LED previousMillis = currentMillis; // if the LED is off turn it on and vice-versa: if (ledState == LOW) ledState = HIGH; else ledState = LOW; // set the LED with the ledState of the variable: digitalWrite(programIndicator, ledState); } } leds[0] = CRGB::Red; leds[1] = CRGB::Orange; leds[2] = CRGB::Yellow; leds[3] = CRGB::Green; leds[4] = CRGB::Aqua; leds[5] = CRGB::Blue; leds[6] = CRGB::Purple; leds[7] = CRGB::Magenta; leds[8] = CRGB::Red; leds[9] = CRGB::Orange; FastLED.show(); delay(60); leds[0] = CRGB::Magenta; leds[1] = CRGB::Red; leds[2] = CRGB::Orange; leds[3] = CRGB::Yellow; leds[4] = CRGB::Green; leds[5] = CRGB::Aqua; leds[6] = CRGB::Blue; leds[7] = CRGB::Purple; leds[8] = CRGB::Magenta; leds[9] = CRGB::Red; FastLED.show(); delay(60); leds[0] = CRGB::Purple; leds[1] = CRGB::Magenta; leds[2] = CRGB::Red; leds[3] = CRGB::Orange; leds[4] = CRGB::Yellow; leds[5] = CRGB::Green; leds[6] = CRGB::Aqua; leds[7] = CRGB::Blue; leds[8] = CRGB::Purple; leds[9] = CRGB::Magenta; FastLED.show(); delay(60); leds[0] = CRGB::Blue; leds[1] = CRGB::Purple; leds[2] = CRGB::Magenta; leds[3] = CRGB::Red; leds[4] = CRGB::Orange; leds[5] = CRGB::Yellow; leds[6] = CRGB::Green; leds[7] = CRGB::Aqua; leds[8] = CRGB::Blue; leds[9] = CRGB::Purple; FastLED.show(); delay(60); leds[0] = CRGB::Aqua; leds[1] = CRGB::Blue; leds[2] = CRGB::Purple; leds[3] = CRGB::Magenta; leds[4] = CRGB::Red; leds[5] = CRGB::Orange; leds[6] = CRGB::Yellow; leds[7] = CRGB::Green; leds[8] = CRGB::Aqua; leds[9] = CRGB::Blue; FastLED.show(); delay(60); leds[0] = CRGB::Green; leds[1] = CRGB::Aqua; leds[2] = CRGB::Blue; leds[3] = CRGB::Purple; leds[4] = CRGB::Magenta; leds[5] = CRGB::Red; leds[6] = CRGB::Orange; leds[7] = CRGB::Yellow; leds[8] = CRGB::Green; leds[9] = CRGB::Aqua; FastLED.show(); delay(60); leds[0] = CRGB::Yellow; leds[1] = CRGB::Green; leds[2] = CRGB::Aqua; leds[3] = CRGB::Blue; leds[4] = CRGB::Purple; leds[5] = CRGB::Magenta; leds[6] = CRGB::Red; leds[7] = CRGB::Orange; leds[8] = CRGB::Yellow; leds[9] = CRGB::Green; FastLED.show(); delay(60); leds[0] = CRGB::Orange; leds[1] = CRGB::Yellow; leds[2] = CRGB::Green; leds[3] = CRGB::Aqua; leds[4] = CRGB::Blue; leds[5] = CRGB::Purple; leds[6] = CRGB::Magenta; leds[7] = CRGB::Red; leds[8] = CRGB::Orange; leds[9 ] = CRGB::Yellow; FastLED.show(); delay(60); // delay(100); // wait for a second break; case 2: { unsigned long currentMillis = millis(); if(currentMillis - previousMillis > intervalThree) { // save the last time you blinked the LED previousMillis = currentMillis; // if the LED is off turn it on and vice-versa: if (ledState == LOW) ledState = HIGH; else ledState = LOW; // set the LED with the ledState of the variable: digitalWrite(programIndicator, ledState); } } Serial.println(hueValue); Serial.println(satValue); leds[0] = CHSV( ((hueValue +8)/4), ((satValue+4)/4), 200); leds[1] = CHSV( ((hueValue +4)/4), ((satValue+8)/4), 175); leds[2] = CHSV( ((hueValue +8)/4), ((satValue+4)/4), 200); leds[3] = CHSV( ((hueValue +4)/4), ((satValue+8)/4), 175); leds[4] = CHSV( ((hueValue +8)/4), ((satValue+4)/4), 200); leds[5] = CHSV( ((hueValue +4)/4), ((satValue+8)/4), 175); leds[6] = CHSV( ((hueValue +8)/4), ((satValue+4)/4), 200); leds[7] = CHSV( ((hueValue +4)/4), ((satValue+8)/4), 175); leds[8] = CHSV( ((hueValue +8)/4), ((satValue+4)/4), 200); leds[9] = CHSV( ((hueValue +4)/4), ((satValue+8)/4), 175); FastLED.show(); delay(100); leds[0] = CHSV( (hueValue +4)/4, (satValue+8)/4, 175); leds[1] = CHSV( (hueValue +8)/4, (satValue+4)/4, 200); leds[2] = CHSV( (hueValue +4)/4, (satValue+8)/4, 175); leds[3] = CHSV( (hueValue +8)/4, (satValue+4)/4, 200); leds[4] = CHSV( (hueValue +4)/4, (satValue+8)/4, 175); leds[5] = CHSV( (hueValue +8)/4, (satValue+4)/4, 200); leds[6] = CHSV( (hueValue +4)/4, (satValue+8)/4, 175); leds[7] = CHSV( (hueValue +8)/4, (satValue+4)/4, 200); leds[8] = CHSV( (hueValue +4)/4, (satValue+8)/4, 175); leds[9] = CHSV( (hueValue +8)/4, (satValue+4)/4, 200); FastLED.show(); delay(100); break; case 3: { unsigned long currentMillis = millis(); if(currentMillis - previousMillis > intervalFour) { // save the last time you blinked the LED previousMillis = currentMillis; // if the LED is off turn it on and vice-versa: if (ledState == LOW) ledState = HIGH; else ledState = LOW; // set the LED with the ledState of the variable: digitalWrite(programIndicator, ledState); } } leds[0] = CRGB::Black; leds[1] = CRGB::Black; leds[2] = CRGB::Black; leds[3] = CRGB::Black; leds[4] = CRGB::Black; leds[5] = CRGB::Black; leds[6] = CRGB::Black; leds[7] = CRGB::Black; leds[8] = CRGB::Black; leds[9] = CRGB::Black; FastLED.show(); delay(60); leds[0] = CHSV( ((hueValue +8)/4), ((satValue+4)/4), 200); leds[1] = CHSV( ((hueValue +4)/4), ((satValue+8)/4), 175); leds[2] = CHSV( ((hueValue +8)/4), ((satValue+4)/4), 200); leds[3] = CHSV( ((hueValue +4)/4), ((satValue+8)/4), 175); leds[4] = CHSV( ((hueValue +8)/4), ((satValue+4)/4), 200); leds[5] = CHSV( ((hueValue +4)/4), ((satValue+8)/4), 175); leds[6] = CHSV( ((hueValue +8)/4), ((satValue+4)/4), 200); leds[7] = CHSV( ((hueValue +4)/4), ((satValue+8)/4), 175); leds[8] = CHSV( ((hueValue +8)/4), ((satValue+4)/4), 200); leds[9] = CHSV( ((hueValue +4)/4), ((satValue+8)/4), 175); delay(100); // wait for a second break; case 4: { unsigned long currentMillis = millis(); if(currentMillis - previousMillis > intervalFive) { // save the last time you blinked the LED previousMillis = currentMillis; // if the LED is off turn it on and vice-versa: if (ledState == LOW) ledState = HIGH; else ledState = LOW; // set the LED with the ledState of the variable: digitalWrite(programIndicator, ledState); } } leds[0] = CRGB::Black; leds[1] = CRGB::Black; leds[2] = CRGB::Black; leds[3] = CRGB::Black; leds[4] = CRGB::Black; leds[5] = CRGB::Black; leds[6] = CRGB::Black; leds[7] = CRGB::Black; leds[8] = CRGB::Black; leds[9] = CRGB::Black; FastLED.show(); delay(30); leds[0] = CRGB::Gold; leds[1] = CRGB::Gold; leds[2] = CRGB::Gold; leds[3] = CRGB::Gold; leds[4] = CRGB::Gold; leds[5] = CRGB::Gold; leds[6] = CRGB::Gold; leds[7] = CRGB::Gold; leds[8] = CRGB::Gold; leds[9] = CRGB::Gold; delay(30); // wait for a second // delay(100); break; case 5: { unsigned long currentMillis = millis(); if(currentMillis - previousMillis > intervalSix) { // save the last time you blinked the LED previousMillis = currentMillis; // if the LED is off turn it on and vice-versa: if (ledState == LOW) ledState = HIGH; else ledState = LOW; // set the LED with the ledState of the variable: digitalWrite(programIndicator, ledState); } } leds[0] = CRGB::Black; leds[1] = CRGB::Black; leds[2] = CRGB::Black; leds[3] = CRGB::Black; leds[4] = CRGB::Black; leds[5] = CRGB::Black; leds[6] = CRGB::Black; leds[7] = CRGB::Black; leds[8] = CRGB::Black; leds[9] = CRGB::Black; FastLED.show(); delay(30); leds[0] = CRGB::Red; leds[1] = CRGB::Orange; leds[2] = CRGB::Yellow; leds[3] = CRGB::Green; leds[4] = CRGB::Cyan; leds[5] = CRGB::Blue; leds[6] = CRGB::Purple; leds[7] = CRGB::Violet; leds[8] = CRGB::Magenta; leds[9] = CRGB::Gold; delay(30); // delay(100); break; } }