I have a range sensor and an addressable LED strip
the concept is the further your hand gets from the strip the more LEDS in the strand light up.
the problem is I can only seem to get it to work in one direction
im sure its something small im missing
#include "LPD6803.h"
#define N_PIXELS 50 // Number of pixels in strand
const int pingPin = 7;
int dataPin = 2;
int clockPin = 3;
LPD6803 strip = LPD6803(50, dataPin, clockPin);
void setup() {
Serial.begin(9600);
strip.begin();
}
void loop() {
uint8_t i;
int duration, v;
pinMode(pingPin, OUTPUT);
digitalWrite(pingPin, LOW);
delayMicroseconds(2);
digitalWrite(pingPin, HIGH);
delayMicroseconds(5);
digitalWrite(pingPin, LOW);
pinMode(pingPin, INPUT);
duration = pulseIn(pingPin, HIGH);
v = (duration/2) / 29.1;
v = map(v,20,0,50,0);
if (v <= 50) {
Serial.println(v);}
else
v = 2;
Serial.println(v);
delay(50);
for(i=0; i<v;) {
if (i<v, i++);
strip.setPixelColor(i,0,0,175);
if (i=v; i>0;) i--)
strip.show();
}
}
unsigned int Color(byte r, byte g, byte b)
{
//Take the lowest 5 bits of each value and append them end to end
return( ((unsigned int)g & 0x1F )<<10 | ((unsigned int)b & 0x1F)<<5 | (unsigned int)r & 0x1F);
}