I'm currently learning Arduino. So right now I'm trying to create an Arduino app that will use buttons, LEDs and RGB.
So I have 2 buttons, 8 LEDs and an RGB. The first button is the function switcher: when you press it the LED will light according to their function. The second button is the function activator so right now here's I want to do:
- Function 1: Turn on/off RED light
- Function 2: Increase RED light brightness by 5; if already at 255, reset at 0
- Function 3: Turn on/off GREEN light
- Function 4: Increase GREEN light brightness by 5; if already at 255, reset at 0
- Function 5: Turn on/off BLUE light
- Function 6: Increase BLUE light brightness by 5; if already at 255, reset at 0
- Function 7: Turn on ALL lights, all brightness to 255
- Function 8: Turn off ALL lights, all brightness to 0
I already started coding and I'm stuck at turning on and off the red light. Here's my code:
const int red = 5;
int b1, b2; //Buttons
int dir = 0;
int light = 11;
int func = 0;
boolean buttonValue = true;
boolean buttonState = true;
void setup() {
pinMode(2, INPUT);
pinMode(3, INPUT);
pinMode(red, OUTPUT);
for (int i = 11; i <= 18; i++) {
pinMode(i, OUTPUT);
}
}
void loop() {
b1 = digitalRead(2);
if (b1 == HIGH) {
dir = 2;
func++;
if (func >= 8)
func = 0;
} else {
dir = 0;
}
digitalWrite(light, LOW);
if (dir == 2 && light < 18) {
light++;
}
digitalWrite(light, HIGH);
delay(200);
}
void function(int pin) {
b2 = digitalRead(3);
switch (func) {
case 1:
if (b2 = true) {
digitalWrite(5, HIGH);
} else {
digitalWrite(5, LOW);
}
}
}