Switch Case Function

Just want to hang out with other Makers and chat about stuff? This is the place to do it.
Post Reply
peteb
Posts: 3
Joined: Tue May 06, 2014 5:32 am
Location: Orange NSW Australia

Switch Case Function

Post by peteb » Wed May 14, 2014 12:13 pm

Hi,

I have some code I'd like some help with if I can. Ill just post the snippet of code of interest.

Code: Select all

  case 584684141:  // Red IR Remote Button
  digitalWrite (headlight, HIGH);
  
  break;
I would like to be able to switch the 'headlight' output on and off using the same case input (the number 584684141 is the decoded code from my IR remote).

This code works great for turning the headlights ON but thats where it stops

Pete

andrew
Freetronics Staff
Freetronics Staff
Posts: 978
Joined: Sun Jul 14, 2013 7:06 am
Location: Melbourne, Australia
Contact:

Re: Switch Case Function

Post by andrew » Wed May 14, 2014 11:04 pm

If the system defaults to headlight off when you start or reset it - then store the status of the headlight in a boolean (true/false).
Then you can quickly test after the case statement if the headlight is on or off, then use digitalWrite to switch it off or on.

Post Reply