Hello all,
I am trying to control various parameters of a WS2813 LED strip. In essence, I want to control the brightness (and other parameters) of the LED strip using a proximity sensor.
I have established the brightness of the LED Strip as int proxcont, but havent figured out how to establish it as a int/variable that can change when included in IF statements (like I attempted at the bottom of the code). As it stands, the brightness of the LED Strip is established in the beginning of the code and doesnt change during the IF statements.. Is there a way that the brightness value of the LED Strips can be controlled by an int? Am I coming at this from the wrong angle?
This is where I am at thus far:
#include <FastLED.h>
#include <NewPing.h>
#define LED_PIN 7
#define NUM_LEDS 151
#define CHIPSET WS2813
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
#define TEMPERATURE_1 Tungsten100W
#define TEMPERATURE_2 OvercastSky
#define PING_PIN 12 // Arduino pin tied to both trigger and echo pins on the ultrasonic sensor.
#define MAX_DISTANCE 120 // Maximum distance we want to ping for (in centimeters). Maximum sensor dista
NewPing sonar(PING_PIN, PING_PIN, MAX_DISTANCE);
int distance;
int proxcont = 0;
const int numReadings = 20 ;
int readings [ numReadings ] ;
int readIndex = 0;
int total = 0;
int average = 0;
int newValue = 0;
int lastpixel = 0;
// How many seconds to show each temperature before switching
#define DISPLAYTIME 20
// How many seconds to show black between switches
#define BLACKTIME 3
void setup() {
delay(1000); // power-up safety delay
Serial.begin(9600);
Serial.println("resetting");
LEDS.addLeds<WS2813,LED_PIN,RGB>(leds,NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(proxcont);
for(int thisReading = 0 ; thisReading < numReadings ; thisReading++) {
readings [ thisReading ] = 0 ; }
}
void loop()
{
distance = sonar.ping_cm();
delay(30); // Wait 50ms between pings (about 20 pings/sec). 29ms should be the shortest delay between pings.
Serial.print("distance: ");
Serial.print(sonar.ping_cm()); // Send ping, get distance in cm and print result (0 = outside set distance range)
Serial.println("cm");
delay(100);
// draw a generic, no-name rainbow
static uint8_t starthue = 0;
fill_rainbow( leds + 0, NUM_LEDS - 5, --starthue, 20);
// Choose which 'color temperature' profile to enable.
uint8_t secs = (millis() / 1000) % (DISPLAYTIME * 2);
if( secs < DISPLAYTIME) {
FastLED.setTemperature( TEMPERATURE_1 ); // first temperature
leds[0] = TEMPERATURE_1; // show indicator pixel
} else {
FastLED.setTemperature( TEMPERATURE_2 ); // second temperature
leds[0] = TEMPERATURE_2; // show indicator pixel
}
FastLED.show();
FastLED.delay(8);
if(distance > 0 && distance <= 5) {
proxcont = 10;
delay(30);
}
if(distance = 6 && distance < 10) {
proxcont = 30;
delay(30);
}
if(distance > 10) {
proxcont = 50;
delay(30);
}
}