I was trying to figuring out how to control the lights on the LED strip while Sim was working on the servo motor.
This two posts were really helpful:
Guide for WS2812B Addressable RGB LED Strip with Arduino | Random Nerd Tutorials
FastLED - How to Control specific LEDs
I still had problems calling an array of lights to control the Addressable LED Strip with Arduino.
I tried calling each light (0,1,3..) but only a few lights lit on the 4 rows out of 15 LED lights that made 60 in total
While Sim was having trouble communicating the value from p5js into Arduino in order to control the servo motor and allow the user to choose their instruments through speech recognition, example based on the value of the piano=255
Later in the week when we met in Sim’ place we played with an existing code and called the array of light by groups instead (example r i<15// i<30 )
Each value of the array is bound to an LED (First value to first LED, second value to second LED,...). You can change the color values in the array as you like. And when you want the LEDs to show the current values in the array, you send them out by using FastLED.show()
Servo motor was still in progress.
code
#include <FastLED.h>
#define NUM_LEDS 60
CRGBArray<NUM_LEDS> leds;
void setup() { FastLED.addLeds<NEOPIXEL,3>(leds, NUM_LEDS); }
void loop(){
static uint8_t hue;
for(int i = 0; i < 15; i++) {
// fade everything out
// leds.fadeToBlackBy(40);
// let's set an led value
leds[i] = CRGB(255,255,255);
// FastLED.delay(0);
}
for(int i = 15; i < 30; i++) {
// fade everything out
// leds.fadeToBlackBy(40);
// let's set an led value
leds[i] = CRGB(255,255,0);
// FastLED.delay(0);
}
for(int i = 30; i < 45; i++) {
// fade everything out
// leds.fadeToBlackBy(40);
// let's set an led value
leds[i] = CRGB(255,0,255);
// FastLED.delay(0);
}
for(int i = 45; i < NUM_LEDS; i++) {
// fade everything out
// leds.fadeToBlackBy(40);
// let's set an led value
leds[i] = CRGB(0,255,255);
// FastLED.delay(0);
}
}
#include <FastLED.h>
#define LED_PIN 2
#define NUM_LEDS 60
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
FastLED.setMaxPowerInVoltsAndMilliamps(5, 500);
FastLED.clear();
FastLED.show();
}
void loop() {
// Turn lights from green to blue from left to right R G B
for (int i=0; i<NUM_LEDS; i++){
leds[i] = CRGB(0, 255 - 4*i, 4*i );
FastLED.setBrightness(2*i);
FastLED.show();
delay(50);
}
// Turn lights from blue to magenta from right to left
for (int i=NUM_LEDS; i>0; i--){
leds[i] = CRGB(4*i,0 , 255-4*i);
FastLED.setBrightness(100-i);
FastLED.show();
delay(50);
}
}