hello all, i,v successfully created color mixing project myself and i,m so happy . and thanks all of you here who helped me in every problem. and now i,m planing to shift dimmer on push buttons and add third button for switch mode but before this topic, i want to fix color,s starting position, last two color,s starting point should be @ 0/dim and first color should be @ full brightened/HIGH. and how can i do this any help will be appreciated, thanks in advance.
here is my code
uint16_t GREEN = 4; //Led's and pins
uint16_t RED = 2;
uint16_t BLUE = 5;
int analog = A0;
int analogState = 0;
const byte button3 = 3;
const byte button4 = 13;
float dimmer = 0;
int button3S;
int button4S;
int mode;
void setup() {
// put your setup code here, to run once:
Serial.print(9600);
pinMode(GREEN, OUTPUT); //Pinmodes of the leds
pinMode(RED, OUTPUT);
pinMode(BLUE, OUTPUT);
pinMode(analog, INPUT);
pinMode(button3,INPUT_PULLUP);
pinMode(button4,INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
analogState = analogRead(analog); //Read the voltage on the Potentiometer
dimmer = (255./1023.) * analogState; //Calculate Write Value for LED
button3S = digitalRead(button3);
button4S = digitalRead(button4);
if(button3S == LOW)
{
delay(300);
mode++;
if(mode>2)
{
mode = 2;
}
}
if(button4S == LOW)
{
delay(300);
mode--;
if(mode<0)
{
mode = 0;
}
}
//BLUE
if (mode == 0) {
analogWrite(BLUE, dimmer);
}
//GREEN
if (mode == 1) {
analogWrite(GREEN, dimmer);
}
//RED
if (mode == 2) {
analogWrite(RED, dimmer);
}
}