I want my LED(WS2811) to dim when the room is bright and [the led] to brighten up when the room is dark. (preferably a linear/smooth transition)
I smushed two builds together. One was how to make a photoresistor work and how to make a LED(WS2811*)* to work.
1)Arduino Elegoo (Arduino Uno but cheaper knock-off version.)
2)Breadboard (big and will post a photo)
3)jumper cables
4)100 microFarad capacitor
5)220 resistor
6)10k resistor
7)WS2811 LED lights (the 5v individual light controlled ones)
Pictures: (NOTE: Orange/Red wires are power, Yellow are data/analog, Black/White are ground)
Whole-
Analog side-
GND & data side-
Photoressitor circuit part-
LED connections-
Here is my code. I got rid of the things that I tried to make the lights dim or brighten depending on the values of the photoresistor. Also if you have feedback just note you have to talk in BABY words because I do not know how to code, I just know very basic concepts.
Also, I got my photoresistor code from this link: https://create.arduino.cc/projecthub/MisterBotBreak/how-to-use-a-photoresistor-46c5eb
I got my LED sketch from FastLED library by Daniel Garcia, and this link: https://create.arduino.cc/projecthub/MisterBotBreak/how-to-use-a-photoresistor-46c5eb
[code]#include <FastLED.h>
int value = analogRead(A0);
#define LED_PIN 13
#define NUM_LEDS 144
#define BRIGHTNESS 64
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
#define UPDATES_PER_SECOND 100
CRGBPalette16 currentPalette;
TBlendType currentBlending;
extern CRGBPalette16 myRedWhiteBluePalette;
extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;
void setup() {
Serial.begin(9600);//photorissitor part of code
delay( 3000 ); // power-up safety delay
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS );
currentPalette = RainbowColors_p;
currentBlending = LINEARBLEND;
}
void PhotoResistor()
{
int value = analogRead(A0);
Serial.println("Analog value : ");
Serial.println(value/8);
}
void loop()
{
PhotoResistor();
ChangePalettePeriodically();
static uint8_t startIndex = 0;
startIndex = startIndex + 1; /* motion speed */
FillLEDsFromPaletteColors( startIndex);
FastLED.show();
FastLED.delay(1 / UPDATES_PER_SECOND);
}
void FillLEDsFromPaletteColors( uint8_t colorIndex)
{
uint8_t brightness = 255;
for( int i = 0; i < NUM_LEDS; ++i) {
leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
colorIndex += 3;
}
}
void ChangePalettePeriodically()
{
uint8_t secondHand = (millis() / 1000) % 60;
static uint8_t lastSecond = 10;
if( lastSecond != secondHand) {
lastSecond = secondHand;
if( secondHand == 5) { currentPalette = myRedWhiteBluePalette_p; currentBlending = LINEARBLEND; }
}
}
// This example shows how to set up a static color palette
// which is stored in PROGMEM (flash), which is almost always more
// plentiful than RAM. A static PROGMEM palette like this
// takes up 64 bytes of flash.
const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
{
CRGB::Red,
CRGB::Red,
CRGB::Gray,
CRGB::Gray,// 'white' is too bright compared to red and blue
CRGB::Green,
CRGB::Green,
CRGB::Black,
CRGB::Black,
CRGB::Red,
CRGB::Red,
CRGB::Gray,
CRGB::Gray,// 'white' is too bright compared to red and blue
CRGB::Green,
CRGB::Green,
CRGB::Black,
CRGB::Black,
};[code]
[/code]