Go Down

Topic: Can't get this switch / case sketch to work. Any ideas? (Read 1 time) previous topic - next topic

PlasticOne

Ok so i scraped the first code redid a lot of it and came up with this layout still not working but i think its in beter shape than the first
Code: [Select]
const int redledPin = 2;
const int greenledPin = 1;
const int blueledPin = 0;
const int buttonPin = 3;
const int buttonPin2 = 4;
int RGB=1;
int RGB2=2;

int prevUp = HIGH;
int prevDn = HIGH;

void setup ()
{
  pinMode (redledPin, OUTPUT);
  pinMode (greenledPin, OUTPUT);
  pinMode (blueledPin, OUTPUT);
  pinMode (buttonPin, INPUT);
  pinMode (buttonPin2, INPUT);
  }

void loop ()
{
int currUp = digitalRead(buttonPin && buttonPin2);

   if(currUp != prevUp)
   {
      delay(25);

      currUp = digitalRead(buttonPin && buttonPin2);


      if(currUp != prevUp)
      {
         if(currUp == LOW)
            RGB++ && RGB2;

      }
   }
   
  switch (RGB){
    case 1:
   switch (RGB2){
    case 1:
    analogWrite(redledPin, 0);
    analogWrite(blueledPin, 250);
    analogWrite(greenledPin, 0);
    break;
     
    case 2:
    analogWrite(redledPin, 0);
    analogWrite(blueledPin, 0);
    analogWrite(greenledPin, 0);
    break;   
   
    case 3:
    analogWrite(redledPin, 250);
    analogWrite(blueledPin, 250);
    analogWrite(greenledPin, 250);
    break;
   
    case 4:
    analogWrite(redledPin, 250);
    analogWrite(blueledPin, 0);
    analogWrite(greenledPin, 250);
    break;
   
    case 5:
    analogWrite(redledPin, 0);
    analogWrite(blueledPin, 250);
    analogWrite(greenledPin, 250);
    break;
  }
    prevUp = currUp;
   
    case 2:
    switch (RGB2){
    case 1:
    analogWrite(redledPin, 0);
    analogWrite(blueledPin, 250);
    analogWrite(greenledPin, 0);
    break;
     
    case 2:
    analogWrite(redledPin, 0);
    analogWrite(blueledPin, 0);
    analogWrite(greenledPin, 0);
    break;   
   
    case 3:
    analogWrite(redledPin, 250);
    analogWrite(blueledPin, 0);
    analogWrite(greenledPin, 0);
    break;
   
    case 4:
    analogWrite(redledPin, 0);
    analogWrite(blueledPin, 0);
    analogWrite(greenledPin, 250);
    break;
   
    case 5:
    analogWrite(redledPin, 0);
    analogWrite(blueledPin, 250);
    analogWrite(greenledPin, 0);
    break;
  }
    prevUp = currUp;
  }
}

PaulS

Code: [Select]
     currUp = digitalRead(buttonPin && buttonPin2);
In English, what is this supposed to be doing? It isn't, but I haven't any idea how to change it, because I have no idea what you think it does.

Code: [Select]
            RGB++ && RGB2;
And this?

Go Up