SparkFun Forums 

Where electronics enthusiasts find answers.

For the discussion of Arduino related topics.
By sadboy
#193160
0
down vote
favorite
I'm currently learning Arduino stuff. So right now I'm trying to create a arduino app that will use buttons, leds and rgb

So I have 2 buttons, 8 leds and a RGB. The first button is the function switcher when you press it the led will light according to their function and 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:
Code: Select all
  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);
}    
 }
 }