![]() ![]() delay program to 20 milliseconds so as to not overload the buffer ![]() print out numerial value to Serial for the output of the LED. Visual Debugger.ĪnalogWrite(redLEDPin, redVal) // write the value of redVal to redLEDPinĪnalogWrite(greenLEDPin, greenVal) // write the value of greenVal to greenLEDPinĪnalogWrite(blueLEDPin, blueVal) // write the value of blueVal to blueLEDPin Pure Red.ĭefault: // if at any point the potVal is out of range or math doesn't work out. Starts at Indigo then fades out blueLED to make Red.Ĭase 6: // potVal has hit 1530 value. Starts at blue then fades in redLED to make Indigo.Ĭase 5: // potVal is in sixth 255 range (1275-1530). Starts at Cyan and then fades out green LED to make blue.Ĭase 4: // potVal is in fifth 255 range (1020-1275). Starts at green then fades in blue LED to make Cyan.Ĭase 3: // potVal is in fourth 255 range (765-1020). Starts at yellow then fades out red LED to make green.Ĭase 2: // potVal is in third 255 range (510-765). Starts at Red, then fades in the green LED to make yellow.Ĭase 1: // potVal is in second 255 range (255-510). Serial.print(wholeNumber) // print wholeNumber to Serial for debuggingĬase 0: // potVal is in first 255 range. will return whole number of how many times the potVal can be divided by 255 for switch statement Serial.print(modVal) // print modVal to Serial for debugging 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 |