Help with christmas project! - photoresistors
emmali55
Posts: 10
Hi, I am trying to program·a boe-bot as a chrstmas surprise.· I would like it to be sitting in a dark room and move forward when the light is turned on.
I don't have much experience with this kind of stuff, but in using the book (Robotics with the Boe-Bot) I was able to program it to "wander towards the light."· If the shadow on the left resistor is more than the shadow on the right, it turns Right, etc.· If shadows are equal it drives straight.·
This is good, but in the dark it just pulses in circles.· Can someone please clue me in to a code that translates: "If·level of shadow is certain number (i.e all dark/no light)·sit still; if light, move forward."
It would be wonderful if I could make this happen before Christmas, I am pretty excited about it.· If you think you can help please let me know! [noparse]:)[/noparse]
I don't have much experience with this kind of stuff, but in using the book (Robotics with the Boe-Bot) I was able to program it to "wander towards the light."· If the shadow on the left resistor is more than the shadow on the right, it turns Right, etc.· If shadows are equal it drives straight.·
This is good, but in the dark it just pulses in circles.· Can someone please clue me in to a code that translates: "If·level of shadow is certain number (i.e all dark/no light)·sit still; if light, move forward."
It would be wonderful if I could make this happen before Christmas, I am pretty excited about it.· If you think you can help please let me know! [noparse]:)[/noparse]
Comments
If you can't figure this out, post your source program as an attachment to your reply.
Mike Green: I like the idea of SLEEP. How would I use it? A combo of GeorgeL's idea with IF THEN ELSE ENDIF?
Such as:
IF light levels (or shadow levels, i suppose?) are xxxx
THEN SLEEP
ELSE drive straight
ENDIF
?
I will post what I have, like you suggested. Maybe that will help. I don't entirely understand which values stand for what. (i.e. FREQOUT 4,2000,3000) so please keep that in mind. [noparse]:)[/noparse] I'm pretty sure what I need to make changes to will be under the "Navigate" heading?
Here is a what I have so far:
DEBUG "Program Running!"
timeLeft VAR Word
timeRight VAR Word
average VAR Word
difference VAR Word
FREQOUT 4, 2000, 3000
DO
GOSUB Test_Photoresistors
GOSUB average_and_difference
GOSUB Navigate
LOOP
Test_Photoresistors:
HIGH 6
PAUSE 3
RCTIME 13,1,timeleft
HIGH 3
PAUSE 3
RCTIME 3,1,timeright
RETURN
average_and_difference:
average = timeRight + timeLeft / 2
difference = average / 6
RETURN
Navigate:
IF (timeLeft > timeright + difference) THEN
PULSOUT 13, 850
PULSOUT 12, 850
ELSEIF (timeLeft > timeleft + difference) THEN
PULSOUT 13, 650
PULSOUT 12, 650
ELSE
PULSOUT 13, 850
PULSOUT 12, 650
ENDIF
PAUSE 10
RETURN
You'll need to figure out the value of the constant "darkThreshold" by experimentation
using a small program that just calls Test_Photoresistors and displays the results using
DEBUG.
LEFT
Bright: 32
Med Shadow: 52
High Shadow: 380
Dark:0
RIGHT
Bright: 20
Med. Shadow: 28
High Shadow: 230
Dark: 0
When using your sleep code, to indicate the darkThreshold, I write --> darkThreshold CON lightlevel? And lightlevel being the Dark, High Shadow, or Med. shadow, right? I must leave now, but will play with the differences next time.
Let me know if I'm on the right track. Thanks again.
Post Edited (emmali55) : 12/20/2008 7:10:54 PM GMT