Now am looking for a way to combine the two together so as that by varying the distance from the sensor changes the colour on the strip eg. No object, white light.... Object halfway, yellow light... Object on surface, colour red... (mere example)
Help, and even code would be greatly appreciated
Thanks.
It is hard to know how to answer this because basically on one hand it is so very simple and on the other it can be complected.
Basically you have numbers that control the LEDs, so instead of taking those numbers from the sketch as fixed values you take them from your input sensor.
Or you take your input sensor value, and then using if statements decide what happens to the LEDs when the input value is with a certain range sort of like this:-
read sensor into variable val
if(val > some value && val < some other value) { do one thing }
if(val > some other value && val < some different other value) { do another thing }
The && is read as AND
Note this is not exactly code but is close enough.
how to I put the sensor reading into the led value
Did you understand the second method?
You don't directly, you do a bit of code depending on what the value is. That's what all the if() statements are about. You send the LED values exactly the same way you are doing it in the first link.
i sort of understand the second bit, so far am able to make one colour with the sensor but that is as far as i can get.
Code i have written:
#define REDPIN 5 #define GREENPIN 6 #define BLUEPIN 3 int IRpin = 1; // analog pin for reading the IR sensor void setup() {
Serial.begin(9600); // start the serial port*
pinMode(REDPIN, OUTPUT);*
pinMode(GREENPIN, OUTPUT);*
pinMode(BLUEPIN, OUTPUT);* } void loop() {
int r, g, b;*
_ float volts = analogRead(IRpin)0.0048828125; // value from sensor * (5/1024) - if running 3.3.volts then change 5 to 3.3_
_ float distance = 27pow(volts, -1.10); // worked out from graph 65 = theretical distance / (1/Volts)S - luckylarry.co.uk_
Serial.println(distance); // print the distance*
delay(100); // arbitary wait ti0me.*
if (distance >= 80) {*
analogWrite(REDPIN, 255);*
analogWrite(GREENPIN, 255);*
analogWrite(BLUEPIN, 255);*
}*
if (distance < 80) analogWrite(GREENPIN, 255);* }
And the resultant is white light stays on and wont change to green
and so on, have you got the tune?
so make up the words
don't quite get that bit but the code i understand, so i have a 10-80cm sensor, so if i make all the values less than 80 where you have greater it should work the same??