Answered: timers and sensors

sent this to another forum but am wondering if it could be answered quicker here:
How do I use a timer to define an occurrence within specific passage of time?
I need to read a light sensor that has registered a level < 50 and continue to read that sensor for 20 seconds(20000 ms)
If this condition happens I then need to start a motor and have it run for 4 minutes then stop(This is the easy part and i have got that sequence figured out)
Then I need nothing to happen until the sensor reads a level of > 300, which reverses the motor sequence from above
Then once again nothing happens until the initial state is reached again.
The robot has to be able to be exposed to the light sensor levels without responding until the following level has been enacted upon.
Source light is a fixture of my design which has its own dusk to dawn sensor.
When the fixture goes on, the robot needs to look at it and when the level is within the defined parameters it needs to raise a curtain exposing the fixture after 20 seconds of exposure
The light will stay on so I cannot have the curtain raise sequence start to happen again or it will tear itself apart.
When the light goes off at dawn, the robot needs to lower the curtain and wait to move again when the light comes back on ad infinitum.
Any suggestions specifically on how to make the robot look and then turn a blind eye until the level changes allowing the curtain to go up but not tear its rigging to pieces after it does?

Unfortunately we can not answer specific programming questions but you should be able to accomplish this using IF / ELSE Statements.

Well after cramming and learning the programming I need to make my project work, all of the sudden my microcontroller has gone south. Is there a way I can get back to square one with firmware etc. When my code block is downloaded, it finishes the output to the controller and then it starts to have fits, trying to run but skipping and stuttering for 5 or six rounds, then it runs, sometimes, but then in the middle of a rather simple group of commands, it messes up again. Needless to say, I am frustrated and have to load in my installation tomorrow but it is looking pretty bleak. I have read other posts that say the microcontroller may be bad, but I do not have another one and there is no time to get one. Anyone run into problems like this?

I isolated it to a power supply I was using though I am still suspicious of the microcontroller, it doesn’t always run the code the same way, drops counts, doesn’t do the math I assigned it etc. I am a bit flustered by its behavior and it almost tore apart the project by responding incorrectly to input. I am using a battery now but it drains very quickly, I think it is bad also. Really trying to do something quite simple, having it look at a light level, count to 30, look again and if the level is still in the same range as it was prior to the count down, run to motors which raise a curtain. Once the curtain is raised, I tell it to look again and if the level of the light sensor is still in the same range as before, send a value of one to x and take away a value of one for y which ends that part of the loop and sends it to the second part which does the same thing but based on a different range for the sensor and it lowers the curtain, then it adds to y and subtracts from x sending it back to the beginning. Pretty simple but it has not rum correctly since the flare up, and the project is outside so the cold really seems to be bothering it. Not sure what to do, wish there was a vex store in the mall or something so I could swap out my controller.

**Yes, to get back to the “Out of Box” state, please refer to the post - Get back to “Square One” on our Forum.

Note: using a Power Supply or Batteries that can not supply the required current will cause issues.**