I am not able to figure out how to make an if-then statement with a sensor. I am using an Adafruit Floraboard. I need a Neopixel to light up if the UV sensor value goes too high. How would I go about programming this?
I don't know what exact commands to use to read your sensor or light up your pixels, but pseudo code something like this:
read the sensor
if (sensor reading > some threshold)
turn on the neopixel
else
turn off the neopixel
Perhaps id you posted you code so far you will get more specific help?
You may need to ad some hysteresis if things sit at the threshold.
if (sensor reading >= threshold)
{
turn on the neopixel
}
else if (sensor reading < threshold - hysteresis )
{
turn off the neopixel
}
OR
if (sensor reading >= threshold - hysteresis)
{
turn on the neopixel
hysteresis = 1; //or some value
{
else
{
turn off the neopixel
hysteresis = 0;
}
Konstantinr:
I am not able to figure out how to make an if-then statement with a sensor. I am using an Adafruit Floraboard. I need a Neopixel to light up if the UV sensor value goes too high. How would I go about programming this?
boolean sensorIsTooHigh = false;
void loop() {
boolean sensorWasTooHigh = sensorIsTooHigh;
sensorIsTooHigh = is_the_sensor_tooHigh();
if(sensorWasTooHigh && !sensorIsTooHigh) {
turn_the_neopixels_off();
}
else if(!sensorWasTooHigh && sensorIsTooHigh) {
turn_the_neopixels_on();
}
// else do nothing - leave the pixels as they are.
}
I'm having trouble using your code because I'm a beginner. Is it possible to point out the mistakes in the photo?
Konstantinr:
I'm having trouble using your code because I'm a beginner. Is it possible to point out the mistakes in the photo?
Please read the "How to use this forum" post at the top of any of the message boards. There it will show you how to post your code where people can help you. A screenshot is not something anyone can work with.
OP's screenshot: