![]() using modulous command we can drop anything more than 255 for assigning to the RGB values. Serial.print(potVal) // print potVal to Serial for debugging map the potentiometer's RAW reading to a range we need for the fader (1530 = 5 steps of 255) Serial.print(potRAW) // print potRaw to Serial for debugging take in the RAW reading from the potentiometer put your setup code here, to run once: Int modVal = 0 // setup modVal variable as int Int wholeNumber = 0 // setup wholeNumber variable as int Int potVal = 0 // setup potVal variable as an int Int potRAW = 0 // setup potRAW variable as int Int blueVal = 0 // value to write to the blue LED Int greenVal = 0 // value to write to the green LED Int redVal = 0 // value to write to the red LED setting up variables to hold the data for each LED leg of the RGB LED ![]() assigning the potentiometer's output to analog pin A0Ĭonst int potPin = A0 // analog pin connected to potentiometer setting up the RGB LED's pins as outputsĬonst int redLEDPin = 10 // red leg of RGB LED connected to pin 10Ĭonst int greenLEDPin = 9 // green leg of RGB LED connected to pin 9Ĭonst int blueLEDPin = 11 // blue leg of RGB LED connected to pin 11 * Keep Arduino Open Source, Share, Comment, and Help Others * Please take the time to read all the comments if you are unsure of exactly what is happening. * No warranty is expressed or implied, use at own risk. * Sketch will output many values to Serial for debugging. * This is a sketch written to display a potentiometer's output and have it adjust a single RGBLED depending on the value/angle of the potentiometer. * Change a single RGB LED with a 10k potentiometer and Rainbow effect Uses switch statements to cycle to the next case. Doesn’t necessarily have to be a potentiometer but any kind of analog input that you can map to the range. Instead of it cycling through automatically I hooked it up to a potentiometer so as you cycle the potVal through it’s range it changes the colour accordingly. I wrote an example sketch a few months back for another user and just stopping by to post in case it helps you out a little. ![]() This is a cool problem to visualize because it follows a sequential pattern of fade up, fade down, do nothing, but this pattern is staggered between each color with no two colors doing the same thing.ĪnalogWrite(green, 255 - i) // fade down It works by using three for loops, inside each of the loops 1 color stays static and the other 2 colors dynamically increase or decrease opposite of one another. There is probably a more efficient way to do it, but this way makes sense to me. There are tons of resources out there to learn how to manipulate them with code but I thought I would share how I get them to fade through the color spectrum. RGB leds where my start to coding with arduino.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |