G+_Tyler Pearson Posted June 23, 2016 Share Posted June 23, 2016 Ive been messing around with the Arduino Collision sensor project and have everything working as intended but I wanted to make a couple changes and have been unable to figure out how I would go about doing it properly. Im new to Arduino and programming so im not 100% sure what I can and cant do with the Fastled library and Arduino. Ive looked at the fastled wiki and documentation but cant seem to find any good info. I found a keyword file in the libraries folder but it doesn't have any explanation for what they do or how to manipulate them. 1. Is there any resources I can look at to explain the library and all the capabilities of it? 2. Can anyone help me head in the right direction towards making my leds light up like i want? I currently have a strip of 40 leds in 5 sets of 8. ( I may increase it to 6 sets of 8 for a total of 48 leds) I would like to get the sets to light up all at the same time based on the range I am getting from the ultrasonic sensor. So something like Mapping the Ultrasonic sensor values to 20-120 If 100 If 80 If 60 If 40 If 20 If 0 I have been able to get them to change colors and do what i want except the leds light up individually based on the distance. Id rather have all 8 leds per strand light up if the ultrasonic sensor is reading anywhere in the range given. So if it reads 120 the first 8 light up green. Currently it will light up only 1 led green and increases as the range value decreases like in Padre's project. Ive though about changing the wiring and making the led strips in parallel instead of series like i currently have but im not sure if that would work and I would have to re solder everything. (Not a big deal but this was my first soldering project and it was a pain to get the led strips soldered in series so i could make it display like i wanted.) I think my issue is with the mapping of the ultrasonic sensor to the led strip. I was hoping I could just make a small change to the project code Padre used but it seems i may have scrap it all and write it in a different way. But I cant seem to find any information on how I would light specific leds on a strip. I usually end up with either nothing working or only 1 out of the 8 leds per strip lighting up. Here is the code padre used for reference. Id post my edits but nothing worked and i really only was able to change the colors to green yellow red at 20% intervals. https://gist.github.com/anonymous/cc27cc806a6d98f6b9aac8e26644977d Here is my current setup to give a visual. Link to comment Share on other sites More sharing options...
G+_Branden Snyder Posted June 23, 2016 Share Posted June 23, 2016 I'm pretty new to Arduino programming. Other people are welcome to chime in! My thougts are: A.) Map the ultrasonic sensor to 0-5 to represent each row of led's. 0 means all rows are off which means int LightMap = map(RangeValue, 0, 120, 0, 5) B.) Set the led's to light based on 0-5. Don't use the "for loop", instead use multiple "if" statements FastLED.clear(); If LightMap >= 1, then led[0-7] = CRGB::Green If LightMap >= 2, then led[8-15] = CRGB::Green If LightMap >= 3, then led[16-23] = CRGB::Yellow etc, etc.... FastLED.show() P.S. this is meant as pseudo-code, not necessarily correct. For example, I have no idea if you can set multiple items at once using led[0-7] Link to comment Share on other sites More sharing options...
G+_Tyler Pearson Posted June 23, 2016 Author Share Posted June 23, 2016 ya i originally did multiple If statements and it worked but I figured there would be a way better way to do it. This was one way I did it and it works but it seems like there should be a better way to do it https://gist.github.com/anonymous/106c173adb81c31336a06d28e68cf324 i also did the multiple map route but it would only light up 1 led out of the led range i gave it. Link to comment Share on other sites More sharing options...
G+_Branden Snyder Posted June 23, 2016 Share Posted June 23, 2016 I think you could do less math. Think of the map() as determining which pre-defined state your lights SHOULD BE off(0), green(1), yellow(2), or red(3) ie. "int LightMap = map(RangeValue, 10, 30, 3, 1);" - the first 2 numbers (10 and 30) are the raw distance values from your sensor, 10cm and 30cm - the 3rd number represents how many predefined states you want - the 4th number is 1 and means that 30cm is the start of your green state, rather than (30 - 10) / 4 = 25cm Toss in some error-correcting for safety ie. "if(LightMap > 3) LightMap = 3; if(LightMap < 0) LightMap = 0;" Then set each state and build off of the previous ie. "int nextLed = 0; if(LightMap = 0) { FastLED.clear(); } if(LightMap >= 1) { for(int x = 0; x < 8; x++){ leds[nextLed] = CRGB::Green; ++nextLed; } if(LightMap >= 2) { for(int x = 0; x < 8; x++){ leds[nextLed] = CRGB::Yellow; ++nextLed; } if(LightMap >= 3) { for(int x = 0; x < 8; x++){ leds[nextLed] = CRGB::Red; ++nextLed; } FastLED.show();" Link to comment Share on other sites More sharing options...
Recommended Posts