/*
Specs:
The project is a light sculpture working with a string of individually addressable WS2812 LEDs
1.Writing a script that controls the light animation. The animation consists of "light points" traveling from one end of the light strip to the other.
Multiple instances of these "light points" will start at somewhat randomized intervals and travel at different speeds.
At certain points in the strip, they should change velocity, color and intensity.
=====
2.Developing a wiring schematic so that the micro-controller can process an input signal from an analog potentiometer
to modulate the number and intervals of traveling "light points".
=======
The "light points" are meant give the illusion of cars driving along at night.
The cars have white headlights and red tail lights.
Before every corner, they slow down and then turn.
For the cars coming down, headlight becomes bright as it is pointed at the viewer, and the tail light disappears.
For the cars going up, the headlight disappears, and the tail light becomes very bright.
When the car has completed the turn, the lights go back to the previous intensity.
The height of the piece is 1,20m and the length of the strip will be 5,35m.
I suppose that each turning point for the cars would have to be defined as a specific LED.
For now, I want to test it with a 60 LEDs/meter strip. For the future, perhaps, I might have to use a 144 LED/meter strip if the animation needs to be smoother, or even a custom PCB.
======Points techniques
EP32 LIB : Oui
Utiliser palettes : https://randomnerdtutorials.com/guide-for-ws2812b-addressable-rgb-led-strip-with-arduino/
Cablage : Puissance, capas... https://fr.aliexpress.com/item/1005003387029674.html?spm=a2g0o.productlist.main.1.4fda147cbJfyVT&algo_pvid=dd328a75-3b0d-4a2a-9f65-2c6a8cd471cc&algo_exp_id=dd328a75-3b0d-4a2a-9f65-2c6a8cd471cc-0&pdp_ext_f=%7B%22sku_id%22%3A%2212000025541846183%22%7D&pdp_npi=2%40dis%21EUR%2130.68%2121.17%21%21%21%21%21%402100bc5c16742566641827007d06d8%2112000025541846183%21sea&curPageLogUid=Xsp6wqca7rzb
SIMULATION : https://wokwi.com/projects/350411655666991699
======Questions :
Cars overtaking?
Date de livraison? 19 février
Tarif? 300?
*/
// On ESP32, use 13 as MOSI : https://randomnerdtutorials.com/esp32-spi-communication-arduino/#esp32-spi-pins
#define LED_PIN 2 //13 or 23 on ESP32
#include <FastLED.h>
#define NUM_LEDS 70 //144*5.35=770
CRGB leds[NUM_LEDS];
CRGB patternCarsDown[2] = {CRGB(200, 10, 10), CRGB(200, 200, 200)}; //tail, head
CRGB patternCarsUp[2] = {CRGB(255, 10, 10), CRGB( 0, 0, 0)}; //tail, head
#define TURN1 20 //Turn positions in the strip
#define NBCARSDN 3
#define NBCARSUP 3
int positionCarsDn[NBCARSDN] = {0};
int positionCarsUp[NBCARSUP] = {0};
void setup()
{
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
//initializing cars (negative) offset on startup
for (int carNum = 0 ; carNum < NBCARSDN; carNum++)
{
positionCarsDn[carNum] =carNum*12;// random(-NUM_LEDS, 0);
}
for (int carNum = 0 ; carNum < NBCARSUP; carNum++)
{
positionCarsUp[carNum] =carNum*12;// random(-NUM_LEDS, 0);
}
}
int carNum = 0;
void loop()
{
//Generating down cars
/*for ( carNum = 0 ; carNum < NBCARSDN; carNum++)
{
positionCarsDn[carNum]= (positionCarsDn[carNum]+1) % (NUM_LEDS-2);
leds[positionCarsDn[carNum] + 0] = CRGB(0, 0, 0);
leds[positionCarsDn[carNum] + 1] = patternCarsDown[0];
leds[positionCarsDn[carNum] + 2] = patternCarsDown[1];
}*/
//Generating up cars
for ( carNum = 0 ; carNum < NBCARSUP; carNum++)
{
positionCarsUp[carNum]= (positionCarsUp[carNum]-1) % (NUM_LEDS-2);
leds[positionCarsUp[carNum] + 0] = patternCarsUp[0];
leds[positionCarsUp[carNum] + 1] = patternCarsUp[1];
leds[positionCarsUp[carNum] + 2] = CRGB(0, 0, 0);
}
FastLED.show();
delay(50);//refresh rate
}