// *************************************************************** // // Project Name: Highly Accurate Coded RGB LED Project // Programming by Sartaj Singh Virdi // Copyright 2020 TechnoTaj // Free to use this code for non-commercial purpose only. // For more information please visit https://www.technotaj.com // Please give credit when using this code. // // *************************************************************** int RED_LED = 9; // Arduino pin for Red LED int GREEN_LED = 10; //Arduino pin for Green LED int BLUE_LED = 11; //Arduino pin for Blue LED int pot1= A0; //Arduino pin for first potentiometer int pot2= A1; //Arduino pin for second potentiometer int pot3= A2; //Arduino pin for third potentiometer void setup(){ pinMode(RED_LED, OUTPUT); pinMode(GREEN_LED, OUTPUT); pinMode(BLUE_LED, OUTPUT); pinMode(pot1, INPUT); pinMode(pot2, INPUT); pinMode(pot3, INPUT); } void loop(){ int Red_Val=analogRead(pot1); // Read the first potentiometer value int Green_Val=analogRead(pot2); // Read the second potentiometer value int Blue_Val=analogRead(pot3); // Read the third potentiometer value Red_Val=(Red_Val/4); // Ensure that the value of first potentiometer value remains under 256 Blue_Val=(Blue_Val/4); // Ensure that the value of second potentiometer value remains under 256 Green_Val=(Green_Val/4); // Ensure that the value of third potentiometer value remains under 256 RGBLED(Red_Val,Green_Val,Blue_Val); //Call the RGB Function with the varied potentiometer value } /* * Function RGBLED(variable color values) */ void RGBLED(int R_RED, int G_GREEN, int B_BLUE){ analogWrite(RED_LED, R_RED); // Illuminate the RED_LED with a varied pot value analogWrite(GREEN_LED, G_GREEN); // Illuminate the GREEN_LED with a varied pot value analogWrite(BLUE_LED, B_BLUE); // Illumiate the BLUE_LED with a varied pot value }