looking for some help doing the following:
having light sensor see specific range of light 20 seconds
run a motor
see a specific range of light again for 20 seconds
reverse motor
return to start
basically I have a large light fixture in a phone booth outside that is responding to a dusk to dawn sensor of its own. When the light goes on, (dusk) the motors respond after the sensor sees a specific range of light for 20 seconds.
the motors lift a curtain revealing the light
light stays on and motors do nothing for the duration (all night)
light goes off and motors lower the curtain(dawn)
start over
It is imperative that the motors only move at these specific times. I have the motor sequencing worked out and all programming within the motor moves is done, that is the easy part. I am having difficulty with the loop that contains the sensor programming and the timer commands.
Any ideas?
Well,
- Which programming language are you using?
I didn’t get your flow properly, but you can do something like
While(SensorValue(blah) <= 127)
{
motor[port1] = 127;
}
the above block says while the sensor is less than 127, move forward. It’s just an example, and the values will need to be tweaked.
using easyC
light goes on
if specific level is read for 20 seconds
motor starts and raises curtain
motor stops after specific encoder rotation is reached
nothing happens until
light goes off
if specific level is read for 20 seconds
motors reverse and lower curtain
motor stops after specific encoder rotation is reached
nothing happens until
loop back to the beginning
monoculture,
It appears to me that the only things you need to time are the 20-second intervals. (You’re using encoders to determine the motor end points, and there’s no obvious reason you can’t have the microcontroller monitoring for the change all the time.)
How about creating an infinite loop containing:
- A loop containing:
a) Wait 1 second
b) If light, add 1 to light counter
c) If dark, reset counter to 0
d) If counter = 21, exit loop
e) Otherwise, go back to beginning of loop - Run the motor to open the curtain,
- A loop containing:
a) Wait 1 second
b) If dark,subtract 1 from light counter
c) If light, reset counter to 21
d) If counter = 0, exit loop
e) Otherwise, go back to beginning of loop - Run the motor to close the curtain,
- Return to step 1.
?
Good Luck,
Eric
Eric,
Am new to easyC, in fact to programming all together so I am unclear as to the way to write some of this idea, especially the counter and the exit loop. Could you write an example of this program so I can better understand syntax and constuction? Hope this is not too much of a request, I am trying to learn as fast as I can and have a deadline that already passed once.
Thanks
Monoculture
Monoculture,
You can’t, by definition, be any newer to it than I am;); I’ve never programmed in EasyC, or any “C”, or “C#”, or programmed a VEX microcontroller in any language. Furthermore, it has been, literally, a couple of decades since I did what I would consider “real” programming of any type. (There was, I admit, a time when I did a fair amount of programming, including writing control systems for instruments. That time, however, was the 1970’s and 1980’s.)
My understanding, mostly from things I’ve read in this Forum, is that EasyC is a graphical tool that provides a means of writing programs that doesn’t require much knowledge of the syntax requirements. How much effort have you put into using EasyC and its internal training materials? I ask for two reasons:
- If you’ve just looked at it and had an :eek: reaction, then asked for someone here to write a code example, you haven’t met the prevailing standard of effort. Folks in this Forum are, as a rule, very helpful to those of us who get stuck while making diligent attempts at things, but there is a reluctance to “spoon feed” newbies.
- If you’ve tried writing code and it doesn’t work, you could post (in this Forum) the code you’ve written and, probably, get several people here to review it and provide specific feedback.
For the reasons stated above, I can’t, at present, write you an example in EasyC. To be absolutely frank about this, I did get an EasyC Version 1 disk in a lot of used VEX equipment I bought on line a couple of weeks ago, but I haven’t even tried to install it yet.
Good Luck,
Eric
Monoculture,
As much as an exercise for myself as to help you, I’ve flowcharted my suggestion:
[ATTACH]2758[/ATTACH]
I hope this is of some help.
Eric
Visio-LightCurtain_es26de9a.pdf (12.3 KB)