Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <FastLED.h>
- #define NUM_LEDS 300
- #define DATA_PIN 5
- #define LED_TYPE WS2812B
- #define COLOUR_ORDER GRB
- #define BRIGHTNESS 64
- CRGB leds[NUM_LEDS];
- TaskHandle_t Left;
- TaskHandle_t Right;
- const int dataChannel = 0;
- const int freq = 5000;
- const int resolution = 8;
- const int M = NUM_LEDS/2; //midpoint of strip
- void setup() {
- FastLED.addLeds<LED_TYPE, DATA_PIN, COLOUR_ORDER>(leds, NUM_LEDS);
- FastLED.setBrightness(BRIGHTNESS);
- Serial.begin(115200);
- ledcSetup(dataChannel, freq, resolution);
- ledcAttachPin(DATA_PIN, dataChannel);
- xTaskCreatePinnedToCore(
- LeftCode, /* Function to implement the task */
- "Left", /* Name of the task */
- 10000, /* Stack size in words */
- NULL, /* Task input parameter */
- 2, /* Priority of the task */
- &Left, /* Task handle. */
- 1); /* Core where the task should run */
- delay(50);
- xTaskCreatePinnedToCore(
- RightCode, /* Function to implement the task */
- "Right", /* Name of the task */
- 10000, /* Stack size in words */
- NULL, /* Task input parameter */
- 5, /* Priority of the task */
- &Right, /* Task handle. */
- 0); /* Core where the task should run */
- }
- void LeftCode(void * pvParameters){
- for(;;){
- Serial.println("Starting Left...");
- for (int i=0; i<M; i++){
- leds[i] = CRGB::Red;
- FastLED.show();
- }
- delay(500);
- for (int i = M-1; i>=0; i--){
- leds[i] = CRGB::Black;
- FastLED.show();
- }
- }
- }
- void RightCode(void * pvParameters){
- for(;;){
- Serial.println("Starting Right...");
- for (int i=M; i<NUM_LEDS; i++){
- leds[i] = CRGB::Green;
- }
- FastLED.show();
- delay(500);
- for (int i=M; i<NUM_LEDS; i++){
- leds[i] = CRGB::Blue;
- }
- FastLED.show();
- delay(500);
- for (int i=M; i<NUM_LEDS; i++){
- leds[i] = CRGB::Red;
- }
- FastLED.show();
- delay(500);
- for (int i=M; i<NUM_LEDS; i++){
- leds[i] = CRGB::Black;
- }
- }
- }
- void loop(){
- vTaskDelay(50);
- }
Advertisement
Add Comment
Please, Sign In to add comment