NobatteryNopower's blog View Details
Archive for December, 2021
Posted by NobatteryNopower | Dec 01, 2021 @ 04:23 AM | 28,617 Views
Edit - Dec 2nd 2021 - It Works!

PWM / RC control of WS2812 leds. (0 min 20 sec)


Code:
#include <FastLED.h>
#define LED_PIN     7
#define NUM_LEDS    16
#define BRIGHTNESS  20
#define LED_TYPE    WS2812
CRGB leds[NUM_LEDS];
int PWMin = 13;
int PWMvalue = 0;
int value=0;

void setup() 
{
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  pulseIn (13, INPUT);
  Serial.begin(9600);
  FastLED.setBrightness(  BRIGHTNESS );
}
void loop() 
{
  
  PWMvalue      = pulseIn(PWMin, HIGH, 20000);
  Serial.println(PWMvalue);
  FastLED.clear();


  if ((PWMvalue >950) && (PWMvalue < 1000))
  {
  leds[0] = CRGB(255, 0, 0);
  FastLED.show();
  delay(1);
  }
  if ((PWMvalue >950) && (PWMvalue < 1300))
  {
  leds[1] = CRGB(255, 69, 0);
  FastLED.show();
  delay(1);
  }
  if ((PWMvalue >950) && (PWMvalue < 1400))
  {
  leds[2] = CRGB(255, 255, 0);
  FastLED.show();
  delay(1);
  }
  if ((PWMvalue >950) && (PWMvalue < 1500))
  {
  leds[3] = CRGB(0, 215, 0);
  FastLED.show();
  delay(1);
  }

  
  if ((PWMvalue >1500) && (PWMvalue < 2000))
  {
  leds[4] = CRGB(0, 215, 0);
  FastLED.show();
  delay(1);
  }
  if ((PWMvalue >1600) && (PWMvalue < 2000))
  {
  leds[5] = CRGB(255, 255, 0);
  FastLED.show();
  delay(1);
  }
  if ((PWMvalue >1700) && (PWMvalue < 2000))
  {
  leds[6] = CRGB(255, 69, 0);
...Continue Reading