Using an Arduino Uno. I am working on a project for my spouse's birthday and having a hard time. I am trying to make some lights turn on and pulse when the lights in the room dim or turn off. I have edited a code that works to make the lights the right color and pulse. Then I made another circuit to get input from the monitor to see what the photoresistor is picking up, and that gave me some numbers to work with. Then I followed someone else's tutorial for a nightlight setup, and got that to work with the numbers I found for the room, but only using a regular, classic style LED.
So my question is,
A. How do I go about taking my current set up and editing it for an LED strand,
and
B. How do I edit these code's to combine them?
Below are the codes that have been working for me, Attached is a picture of the circuit that works for the regular LED bulb. I am hoping to stay close to that circuit as I am a total newbie and I need to get this done by tomorrow night. The strip is a 5V strip with Ground, Power and DataIn cut to only use about 9 LEDs.
nightlight
Code: Select all
int led = 13;
int ldr = A0;
int value;
void setup() {
pinMode(led, OUTPUT);
pinMode(ldr, INPUT);
}
void loop() {
value = analogRead(ldr);
if (value < 500){
digitalWrite(led, HIGH);
}
else{
digitalWrite(led, LOW);
}
delay(100);
}
Code: Select all
// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit...if you must, connect GND first.
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
#include <avr/power.h>
#endif
#define PIN 6
#define NUMPIXELS 60
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
// This is for Trinket 5V 16MHz, you can remove these three lines if you are not using a Trinket
//#if defined (__AVR_ATtiny85__)
// if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
// #endif // defined __AVR_ATtiny85__
// Initialize the library
strip.begin();
// Send updates to the strip
strip.show();
// Set color to teal
}
void loop() {
// whatever number is here, divide by 2
// that's about how long it should take for the loop to complete
pulse(16);
}
// @param wait the time to wait between the brightness updates (in milliseconds)
// @param color the color to pulse
void pulse(uint8_t wait) {
fadeIn(wait);
// uncomment this if you want it to stay bright for some time
delay(5000);
fadeOut(wait);
// uncomment this if you want it to stay dim for some time
delay(5000);
}
// When brightness is updated, not all pixels get the update sometimes
// This makes sure it does
void rerenderStrip(uint16_t accumulator) {
for (uint16_t i = 0; i < strip.numPixels(); ++i) {
strip.setPixelColor(i, strip.Color(0, accumulator & 255, accumulator & 255));
}
strip.show();
}
// @param wait the time to wait between the brightness updates (in milliseconds)
void fadeIn(uint8_t wait) {
for (uint16_t i = 0; i < 256; ++i) {
// Rerender the full strip so to ensure all pixels are updated
rerenderStrip(i);
delay(wait);
}
}
// @param wait the time to wait between the brightness updates (in milliseconds)
void fadeOut(uint8_t wait) {
for (uint16_t i = 255; i >= 0; --i) {
// Rerender the full strip so to ensure all pixels are updated
rerenderStrip(i);
delay(wait);
}
}