![]() For this we will use the Serial.print() function. delay(50) įinally, to check on what RGB values are being shown on the LED we will print them in the serial monitor.įor the sake of clarity, these will be printed in a single line. You can adjust this delay as you like, just note that too big of a delay will make the RGB values update slower too. This delay last 50 milliseconds: 50 thousandths of a second or 0.05 seconds. Next I introduce a small delay to the code, I do this to prevent the serial monitor from scrolling too fast while still letting the RGB LED feel responsive to inputs. Sets the individual colors with the pot values In this step I use the PWM outputs of the Arduino to light up the red, green and blue pins on the RGB led with the integer values obtained from the potentiometers, you just need to specify the pin and the number between 0 and 255. When the pot is in the leftmost position, the voltage reading is 0V Unfortunately, to control the LEDs with the analogWrite() function we need to feed it values between 0 and 255, to do this we divide the read value by 4 and assign it to our integers. The first step is to define the relevant pins, this is done through the #define statement which will replace the defined keyword with our desired value when the program compiles. ![]() > Read our guide about What You Can Build with Adruino. Serial.print("\tB: ") Serial.println(blueVal) ![]() Final value is Serial.println to create a new line between readings Serial.print("\tG: ") Serial.print(greenVal) The \t character creates a tab space between colors Serial.print("R: ") Serial.print(redVal) Printing the values of Red, Green and Blue in a single line When the pot is in the leftmost position, the voltage reading is 0 Int redVal, greenVal, blueVal //RGB component values *Example sketch to control an RGB LED with Arduino using potentiometers You can upload the following code through the Arduino IDE, you can copy the code by clicking on the button in the top right corner of the code field.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |