Subject:
|
Re: Possible bug? Simple light sensor condition checking.
|
Newsgroups:
|
lugnet.robotics.rcx.legos
|
Date:
|
Mon, 16 Jul 2007 17:14:42 GMT
|
Viewed:
|
16598 times
|
| |
| |
> At 11:13 AM 7/16/07, Timothy Su wrote:
> > I tried my own skill on writing a program for the included lego test pad (RIS
> > 2.0), and I discovered something weird. The following code does set the
> > conditions right, but the following code doesn't set the conditions right if I
> > comment out the 'cputs("");'. Any idea why?
It looks to me like the c compiler optimized the assignment to the
variable away, since there is no external method call
(shutdown_requested() is just a macro).
> >
> > int offonpad =0;
You should make this
volatile int offonpad = 0;
> > while(!shutdown_requested()) {
> > if(LIGHT(LIGHTSENS) < 40) {
> > offonpad = 1;
> > }
> > else {
> > offonpad = 0;
> > }
> > //cputs("");
> > }
You should also put an msleep(10) or at least a yield() somewhere
inside the loop; otherwise it uses up its full time-slice without
letting any other thread react to the change of the variable. You can
tweak the sleep time to balance between reaction time and cpu usage.
Regards,
Jochen
--
Jochen Hoenicke,
Email: hoenicke@informatik.uni-freiburg.de
|
|
Message is in Reply To:
3 Messages in This Thread:
- Entire Thread on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|