Jump to content
43oh

Change led with button


Recommended Posts

Thanks for the help. But will this code work on ccs. I am not use IAR. And i am also not useing rgb leds. But i dont think that matters. I am actually using two sets of red blue and green leds. Each set on a different pin so i can have half red and half green. I aready figured out the code for that. It is just the sequence at the end i am haveing truble with. Thanks alot.

 

-Dan

Link to post
Share on other sites
Why break;? I'm still learning.

 

A break is required to end a case block.

 

switch(n) {
 case 1:
   // do something if n == 1
   break;
 case 2:
   // do something if n == 2
   break;
}

 

switch(n) {
 case 1:
   // do something if n == 1
 case 2:
   // do something if n == 1 or n == 2
 case 3:
   // do something if n == 1 or n == 2 or n == 3
   break;
}

 

You could do this, but it is rather inefficient...

void delay_ms(unsigned ms)
{
 switch(ms) {
   case 10: __delay_cycles(100000);
   case 9: __delay_cycles(100000);
   case 8: __delay_cycles(100000);
   case 7: __delay_cycles(100000);
   case 6: __delay_cycles(100000);
   case 5: __delay_cycles(100000);
   case 4: __delay_cycles(100000);
   case 3: __delay_cycles(100000);
   case 2: __delay_cycles(100000);
   case 1: __delay_cycles(100000);
 }
}

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...