Shop OBEX P1 Docs P2 Docs Learn Events
Help with christmas project! - photoresistors — Parallax Forums

Help with christmas project! - photoresistors

emmali55emmali55 Posts: 10
edited 2008-12-20 19:01 in BASIC Stamp
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]

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-19 22:35
    The BoeBot code for wandering uses the RCTIME statement to read the value of the photoresistor. This value goes up in the dark. You just need to experiment to see what the value is for the darkness level you want. If both photoresistor values are greater than this number, then your program should do a SLEEP for a short time (like a second or so), then go back and check the photoresistors again.

    If you can't figure this out, post your source program as an attachment to your reply.
  • SRLMSRLM Posts: 5,045
    edited 2008-12-19 23:15
    Let me guess: present delivery system? If so, you could get some longer screws, some small tubing, and a piece of wood to make a nice little platform on top.
  • GeorgeLGeorgeL Posts: 131
    edited 2008-12-20 06:03
    "Let me guess: present delivery system? " Thats Santas job...dont steal it. On the other hand a quick and durty solution, calculate some values and do a IF THEN ELSE ENDIF type deal.
  • emmali55emmali55 Posts: 10
    edited 2008-12-20 16:37
    Thanks for your help. present delivery system: how did you guess!? I plan on pulling a little rolly cart, holding the present, behind the BoeBot. It is just a video game so it won't be too heavy. I also have an LCD Screen programmed to scroll a little message. This is all new ot me so I am just anxious to get it all together!

    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
  • emmali55emmali55 Posts: 10
    edited 2008-12-20 16:57
    If this helps... The pins I am using for photoreistors are 3 and 13
  • Mike GreenMike Green Posts: 23,101
    edited 2008-12-20 17:06
    Replace "GOSUB Test_Photoresistors" with
    DO
       GOSUB Test_Photoresistors
       IF timeRight > darkThreshold AND timeLeft > darkThreshold THEN
          NAP 6 ' Sleep for about one second, then repeat loop
       ELSE
          EXIT ' Continue with rest of program
       ENDIF
    LOOP
    


    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.
  • emmali55emmali55 Posts: 10
    edited 2008-12-20 19:01
    Thank you. I am working with it. It didn't work completely - kind of pulsed side to side. I also tried using the "Flashlight Controlled Boe-Bot" program. I can then just set the light levels as I need.··I·am getting somewhere - it pulses forward instead·or driving reg. speed forward.·I am still playing with the light levels. When I measured them, I got the following:
    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
Sign In or Register to comment.