LDR with the WS2812 B LED's. Question as to how to use with the dreaded Arduino(I know, wrong place)
NWCCTV
Posts: 3,629
I know this is the Parallax forum but trying to get an answer from the Arduino forum has been futile at best. I posted a question 2 weeks ago and still no answer. So, I thought I would ask the brainiacs here if you can get me started. I am trying to get an LDR (Light Dependent Resistor) to work with the WS2812B LED's. I have them working independently of each other but I can not figure out how to get them to work together. Basically I am just trying to use an "If" statement. if (sensorReading<100)) then start the WS2812 program. If anyone can give me a hint as to how to get this started I would be ever so grateful. It does not need to be anything fancy, all I need is a starting point. Thanks in advance for the help.
Comments
I think it should look like this.
if (sensorReading < 100)
{
// WS code
}
I had that part figured out. It was the WS code I had issues with but I resolved it. Pretty basic stuff really but I have been away for a while!!!
What are u using for the ws2812 control. fastled or the adafruit library?
#include <FastLED.h>
const int pingPin = 7; // ping in
#define NUM_LEDS 6 // How many leds in your strip?
#define DATA_PIN 2 // What pin is the NeoPixel's data line connected to?
CRGB leds[NUM_LEDS]; // Define the array of leds
void setup() {
// initialize serial communication:
Serial.begin(9600);
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
}
void loop()
{
// establish variables for duration of the ping,
// and the distance result in inches and centimeters:
long duration, inches, cm;
// The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
// The same pin is used to read the signal from the PING))): a HIGH
// pulse whose duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
// convert the time into a distance
inches = microsecondsToInches(duration);
cm = microsecondsToCentimeters(duration);
Serial.print(inches);
Serial.print("in, ");
Serial.print(cm);
Serial.print("cm");
Serial.println();
if (inches <= 20) {fill_solid( &(leds[0]), NUM_LEDS /*number of leds*/, CRGB::Red); //{whitestrobe(30);
FastLED.show();
}
else if (inches >= 21) {fill_solid( &(leds[0]), NUM_LEDS /*number of leds*/, CRGB::Green);
FastLED.show();
}
delay(100);
}
long microsecondsToInches(long microseconds)
{
return microseconds / 74 / 2;
}
long microsecondsToCentimeters(long microseconds)
{
return microseconds / 29 / 2;
}