switch case newb

never used a switch case statement before I basically want to increase a PWM value with a button press. however im getting a error. the example code in the IDE wasn't helpful to me.

 if (dimmerPin==LOW);{
    delay(10);
    count++;
      if (count = 4);{
        count = 0;
      }
  }
   switch 
    case count = 0
      dimmerVal = 64;
      break;
    case count = 1:   
      dimmerVal = 128;
      break;
    case count = 2:    
      dimmerVal = 192;
      break;
    case count = 3:
      dimmerVal = 255;

When you encounter an error you'll see a button on the right side of the orange bar "Copy error messages". Click that button. Paste the error in a message here USING CODE TAGS (</> button on the toolbar).

The correct syntax for switch can be found here.

Once you get the switch case syntax correct you won't be doing much switching until you fix these two errors.

[code]if (count = 4);{

cattledog:
Once you get the switch case syntax correct you won't be doing much switching until you fix these two errors.

[code]if (count = 4);{

And this oneif (dimmerPin==LOW);{

DKWatson:
The correct syntax for switch can be found here.

Thank you, new code compiles with no errors

int count;
int dimmerVal;
int ledPin = 0;    //analogWrite
int dimmerPin =3;  //digitalRead
int lightPin = 2;  //analogRead
int auxPin = 4;    // digitalWrite


void setup() {
  // put your setup code here, to run once:
  pinMode(dimmerPin,INPUT);
  pinMode(lightPin,INPUT);
  pinMode(ledPin,OUTPUT);
  pinMode(auxPin,OUTPUT);

  count = 3;
  
}

void loop() {
  // put your main code here, to run repeatedly:

  if (dimmerPin,LOW);{
    delay(25);
    count++;
      if (count == 4);{
        count = 0;
      }
  }
   switch (count){
    case 0: 
      dimmerVal = 0;
      break;
    case 1:   
      dimmerVal = 85;
      break;
    case 2:    
      dimmerVal = 170;
      break;
    case 3:
      dimmerVal = 255;
      break;  
}
}

if (dimmerPin,LOW)

No, the comma operator is not what you want there.

I think you meant

if (digitalRead(dimmerPin)==LOW)

You must read the pin, and then check the value you get.

Since LOW is just #defined to 0, you can also do

if(!digitalRead(dimmerPin))

But that's not best practice, as it makes the code a bit less readable for no particular benefit.

DrAzzy:
if (dimmerPin,LOW)

No, the comma operator is not what you want there.

I think you meant

if (digitalRead(dimmerPin)==LOW)

You must read the pin, and then check the value you get.

Since LOW is just #defined to 0, you can also do

if(!digitalRead(dimmerPin))

But that's not best practice, as it makes the code a bit less readable for no particular benefit.

good call.

It may compile without errors, but this is still not going to do what you want it to...

if (dimmerPin,LOW);{

Regards,
Ray L.

RayLivingston:
It may compile without errors, but this is still not going to do what you want it to...

if (dimmerPin,LOW);{

Regards,
Ray L.

yes thank you, it has been corrected. sometimes I get in a hurry and forget the little things.
I did grasp the idea of how to set up a switch case, which was my original predicament

LandonW:
yes thank you, it has been corrected. sometimes I get in a hurry and forget the little things.
I did grasp the idea of how to set up a switch case, which was my original predicament

Did you also note that the ; does NOT belong in that statement?