To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.legosOpen lugnet.robotics.rcx.legos in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / legOS / 187
186  |  188
Subject: 
Read me first! Re: case statement doesn't work- any clue?
Newsgroups: 
lugnet.robotics.rcx.legos
Date: 
Mon, 3 May 1999 15:40:40 GMT
Viewed: 
3798 times
  
Nevermind. Dangit. Forgot break statements like a moron.
-Luis

On Mon, 3 May 1999, Luis Villa wrote:

> I'm trying to program some very rudimentary debugging stuff- just
> outputting variables to the screen. Basically, I want to use a switch/case
> statement to read an integer variable (in this case ID_number)
> which is then linked (by the case statement) to universal variables
> elsewhere in the code. Each case should output it's ID#, and then the
> value of the variable which has been ID'd. Then it should wait for the
> next button push to output the next variable.
> 
> The problem is that the case statement appears to fail completely.
> Instead of outputting one value and then incrementing ID_number and
> waiting, it outputs all the values, and *then* waits for the button push ,
> as if they were a continuous list and not a case statement. Is this just
> poor coding on my part? Is this one of these hidden C/C++ differences? Or
> is this another LegOS limitation? (I'm leaning towards the last, but have
> not had a change yet to test this more generally.)
> 
> The applicable code is below. If you'd like to grab the .srec, it's at
> http://arthurdent.dorm.duke.edu/legos/code/light-brait-w-debug.srec
> 
> Thanks ahead of time!
> -Luis
> P.S. I tried incrementing both inside the case statement (as the attached
> code shows) and after the case statement. Neither one worked.
> 
> int variable_output()
> {
>   int ID_number=0; //for the switch statement
> 
>   while(1)
>     {
>       wait_event(&button_press_wakeup,BUTTON_PROGRAM); // wait for PROG
> 
>       switch(ID_number)
>  {
>  case 0:
>    //this should only run the first time the debugger is activated
>    {
>      cputs("debug");    //indicate start
>      lcd_refresh();
>      ID_number=1;  //increment the counter to the next variable
>    }
>  case 1:
>    //light sensor #1
>    {
>      cputs("light");  //outputs "light" then "1" to ID the variable
>      lcd_refresh();
>      msleep(300);
>      new_lcd_int(1,PRINT_TIME);
> 
>      new_lcd_int(LIGHT_1,PRINT_TIME); //this time is irrelevant
> and should be removed once I confirm the code works
>      ID_number+=1;  //increment the counter to the next variable
>    }
>  case 2:
>    //light sensor #2
>    //since this is the last case, the counter is returned to 1
> instead of being incremented
>    {
>      cputs("light");  //outputs "light" then "1" to ID the variable
>      lcd_refresh();
>      msleep(300);
>      new_lcd_int(2,PRINT_TIME);
> 
>      new_lcd_int(LIGHT_2,PRINT_TIME);
>      //PRINT_TIME is irrelevant here-
>      //the code will wait for the button press no matter what.
> 
>      ID_number=1;  //resets the counter to begin the loop again
>    }
> 
>    cputs("test");
>    lcd_refresh();
> 
>     wait_event(&button_release_wakeup,BUTTON_PROGRAM); // wait for PROG
> button to be released
> 
>    //maybe code in an exit case?
> 
>  }
>     }
> }
> #######################################################################
> 
>  God was my co-pilot,
>    but we crashed in the mountains
>         and I had to eat him.
>  -bumper sticker
> 
> #######################################################################
> 
> 

#######################################################################

God was my co-pilot,
  but we crashed in the mountains
       and I had to eat him.
-bumper sticker

#######################################################################



Message is in Reply To:
  case statement doesn't work- any clue?
 
I'm trying to program some very rudimentary debugging stuff- just outputting variables to the screen. Basically, I want to use a switch/case statement to read an integer variable (in this case ID_number) which is then linked (by the case statement) (...) (27 years ago, 3-May-99, to lugnet.robotics.rcx.legos)

3 Messages in This Thread:


Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR