Switch case syntax help needed


hello all,

i've discovered arduino stuff , having ton of fun it.  once receive board , run tests, i'll post project in case interested.

i'm having trouble establishing switch case structure , need know if following valid.  i've read switch case doc, either doc doesn't cover or i'm trying switch case can't handle.  please let me know if possible , syntax real.

voltsin = analogread(15)
switch (voltsin) {
 case voltsin < 12:
 // something
 break;

 case 12 < voltsin <= 18:
 // else
 break;

 case voltsin > 18:
 // third thing
 break;
}

cheers!

you're trying c "case" statement doesn't support; use nested ifs instead:
code: [select]
if (voltsin < 12) {
 //something
} else if (voltsin <=18) {
 //something else
} else if (voltsin > 18) {
 //a third thing
}

you realize have work analogin value before accurately corrospond unit 'volts' ?


Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Switch case syntax help needed


arduino

Comments