![]() Programming an Arduino is very easy with the Adafruit NeoPixel library. ![]() With over 65,000 colours and the ability to change the colours in a whole string 100 times a second there are few constraints on what can be done. LEDs are hooked up to +5V instead of GndĪnalogWrite(redPin, redVal) // Write current values to LED pinsĭelay(wait) // Pause for 'wait' milliseconds before resuming the loopĪnyway, just looking for the fastest code to run on the Arduino.It is time to enter the wonderful world of NeoPixels. ![]() we do "255-redVal" instead of just "redVal" because the PinMode(redPin, OUTPUT) // sets the pins as output Int wait = 15 // 50ms (.05 second) delay shorten for faster fades Int greenVal = 1 // Initial values are all off Int redVal = 1 // Variables to store the values to send to the pins Int bluePin = 11 // Blue LED, connected to digital pin 11 Int greenPin = 10 // Green LED, connected to digital pin 10 Int redPin = 9 // Red LED, connected to digital pin 9 * originally "dimmingLEDs" by Clay Shirky * The program cross-fades slowly from red to green, green to blue, and blue to red * Code for cross-fading 3 LEDs, red, green and blue, or one tri-color LED, using PWM I used Clay Shirky's original program and modified it so I given credit, even though what I end up with is completely different. It's a little clunky, but it gives a fade between all seven ccolors and Black (All Off) and White (All On). Will implemeting Boolean math speed up or slow down the loops? I creaated this small sketch, but don't have the arduino yet to test. Of course, controlling an RGB led is exactly the same as controlling 3 individual LEDs of red, green, and blue colors since RGB leds literally are 3 leds in one package. uses BLDA to implement software based PWM LED dimming across many LEDs driven through an LED driver chip (FlickerBrightness class), and then it uses BLDA to allow arbitrary fading of the LEDs in the ChangeBrightness class (the other class "CCShield" controls the LED driver chip). The code here: Google Code Archive - Long-term storage for Google Code Project Hosting. But to do it efficiently using integers requires a fundamental algorithm called Bresenham's line drawing algorithm (BLDA) Bresenham's line algorithm - Wikipedia which I urge you to look at if you don't know it because it is awesomely useful for highly embedded development! You can do this using floating point math pretty easily using the standard line equation y=mx+b. ![]() So each LED is really drawing a line through a 4 dimensional color-and-time space, where the origin is (say) black and each axis corresponds to R, G and B colors. the rate of fading must be different with each LED because they may have different "distances" to go). Let's put this on steroids and say that what we really want is to fade multiple LEDs simultaneously from arbitrary individual colors to other arbitrary colors, and to finish fading at EXACTLY the same time (i.e. Of course, you can always just increase the delay() amount. It looks like all of the algorithms posted here are missing this situation. Int ledPin = 13 // choose the pin for the LEDīut what happens when you want the LEDs to fade more slowly than 1/1024 the speed of your delay()? In other words, what if your increment should be less than 1 per loop? *note: the vid has the fade time set at a constant, but the code here gives the fade time a random value each time around, if you want a constant value for fade time, just get rid of the "x = random(3, 9) " in the loop, and add "= whatever" to the "int x" at the opening of the code, replacing whatever with a number (good values are between 2 and 15)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |