4 Replies - 1308 Views - Last Post: 11 June 2010 - 01:31 PM Rate Topic: -----

#1 Kabanga  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-March 09

switch .....case statement

Posted 11 June 2010 - 01:15 AM

Hi everyone,
I have 0x00 ...0xFF bytes(256) but I'd like to use them for 300 cases
like this:
switch(cmd)
{
  case 1:
  break;

  ......

  case 300:
  break;

}//end switch(cmd)




Can somebody tell me how to solve that problem?

Thanks for your help
Kabanga
Is This A Good Question/Topic? 0
  • +

Replies To: switch .....case statement

#2 Charles:)  Icon User is offline

  • D.I.C Head

Reputation: 84
  • View blog
  • Posts: 195
  • Joined: 26-November 09

Re: switch .....case statement

Posted 11 June 2010 - 04:18 AM

If I've understood your question properly then I'd probably do something more like this:

for (int i = 1; i <= 300; i++)
{
    if (cmd == i)
    {
        // Logic goes here
    }
}



Your question's a bit vague so I might have misunderstood what you're trying to do.
Was This Post Helpful? 0
  • +
  • -

#3 Kabanga  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-March 09

Re: switch .....case statement

Posted 11 June 2010 - 05:27 AM

Thanks for your answer.

Yeah, your are right about my question.

What I want to do is the following:
I have a PC application (C#) which is sending bytes (0x00 -- 0xFF) to a microcontroller through USB port.
These bytes are used to switch on and off 300 LEDs.
On the firmware side which is loaded in the microcontroller I'd like to use "switch()...case" statements to control these LEDs
I'd like to use one "switch()...case" for every LED. So, I must have 300 "switch()..case" statements.

The "for loop" wouldn't work for me because after a LED has been switched on, the microcontroller should send an acknowledgement byte to the host.
After acknowledgement has been sent, the endpoints of USB port of the microcontroller should be reseted to prepare them to receive new data. And
I think it would be difficult doing that in a "for loop".

So the structure of the "switch()..case" statements on the firmware side(microcontroller) would be:

switch(command)
{
  case 1:
  {
    //switch on LED1

    //send one byte acknowledgement to the host
   
    break;
  }//end case 1

  .....
  .....




  case 300:
  {
    //switch on LED300

    //send one byte acknowledgement to the host
    
    break; 
  }//end case 300

}//end switch(command)





Thanks a lot and best regards
Kabanga
Was This Post Helpful? 0
  • +
  • -

#4 Momerath  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 996
  • View blog
  • Posts: 2,392
  • Joined: 04-October 09

Re: switch .....case statement

Posted 11 June 2010 - 06:03 AM

Isn't the code to send a byte the same for all the LEDs? Wouldn't a method that takes the LED # to turn on and turn it on be much better, rather than writing the same code 300 times (with minor variations)?
Was This Post Helpful? 0
  • +
  • -

#5 Kabanga  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 05-March 09

Re: switch .....case statement

Posted 11 June 2010 - 01:31 PM

thanks for the idea using a method.
I'll give it a try.

Regards
Kabanga
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1