Shop OBEX P1 Docs P2 Docs Learn Events
Barn door code (really concrete plant) — Parallax Forums

Barn door code (really concrete plant)

[Deleted User][Deleted User] Posts: 0
edited 2006-10-27 00:38 in BASIC Stamp
dave,
·does this make it any more readable

thanks


Post Edited (truckwiz) : 10/27/2006 3:03:26 PM GMT

Comments

  • allanlane5allanlane5 Posts: 3,815
    edited 2006-10-25 19:19
    Who would want to make a flower out of concrete?

    Edit:· Earlier, this topic was "Concrete Plant".· Now, it's "Barn Door".· I still don't see a question.

    Post Edited (allanlane5) : 10/26/2006 2:08:17 PM GMT
  • [Deleted User][Deleted User] Posts: 0
    edited 2006-10-25 23:17
    ok,
    ·here's the problem , if any of the animals stop in the doorway they will keep being counted, anybody have any thought's on this.



    Thank's Brian


    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    'this is a program that let's my farm animals in & out ,they all use their own doors
    ' some move faster & slower than each other , a couple are ready to have babies
    doorcnt·· VAR Word
    dogs····· VAR Word
    cats····· VAR Word
    pigs····· VAR Word
    horses··· VAR Word
    door1···· VAR Word··········· 'is door 1 open
    door2···· VAR Word··········· 'is door 2 open
    door3···· VAR Word··········· 'is door 3 open
    door4···· VAR Word··········· 'is door 4 open
    dogcnt··· CON 5············ 'number of dogs
    catcnt··· CON 6············ 'number of cats
    pigcnt··· CON 7············ 'number of pigs
    horsecnt· CON 9············ 'number of horses

    INPUT 1··················· 'dog door photoeye
    INPUT 2···················· 'cat door photoeye
    INPUT 3···················· 'pig door photoeye
    INPUT 4···················· 'horsedoor photoeye
    INPUT 15··················· 'timer on doors

    LOW 5······················ 'dog door lock
    LOW 6······················ 'cat door lock
    LOW 7······················ 'pig door lock
    LOW 8······················ 'horse door lock

    allDoorshut:
    · IF IN15 = 1 THEN allDoorshut·················· 'is it time to open doors ?
    · OUT5=1········································ 'open dog door
    · OUT6=1········································ 'open cat door
    · OUT7=1········································ 'open pig door
    · OUT8=1········································ 'open horse door
    · doorcnt =%0000································ 'all doors open
    · DO
    · GOSUB cntdog
    ···· IF dogs => dogcnt THEN door1 = %0001······· 'is dog door closed
    · GOSUB cntcat
    ···· IF cats => catcnt THEN door2 = %0010······· 'is cat door closed
    · GOSUB cntpigs
    ···· IF pigs => pigcnt THEN door3 = %0100······· 'is pig door closed
    · GOSUB cnthorses
    ···· IF horses => horsecnt THEN door4 = %1000··· 'is horses door closed
    ···· IF dogs => dogcnt THEN OUT5=0·············· 'if all dogs in close door1
    ···· IF cats => catcnt THEN OUT6=0·············· 'if all cats in close door2
    ···· IF pigs => pigcnt THEN OUT7=0·············· 'if all pigs in close door3
    ···· IF horses => horsecnt THEN OUT8=0·········· 'if all horses in close door4
    ······ doorcnt = door1 | door2 | door3 | door4·· 'check all doors
    ···· IF doorcnt= %1111 THEN allDoorshut········· 'are all doors shut,if they are go wait at alldoorshut

    ·· LOOP
    ·· cntdog:
    ··· IF IN1 = 1 THEN addDogCnt··················· 'count dogs
    ···· RETURN
    ····· addDogCnt:
    ······ dogs = dogs + 1
    ······· RETURN·································· 'check other animals
    · cntcat:
    ·· IF IN2 = 1 THEN addCatCnt···················· 'count cats
    ··· RETURN
    ···· addCatCnt:
    ····· cats = cats + 1
    ······· RETURN·································· 'check other animals
    ·· cntpigs:
    ··· IF IN3 = 1 THEN addPigCnt··················· 'count pigs
    ···· RETURN
    ····· addPigCnt:
    ······ pigs = pigs + 1
    ······· RETURN·································· 'check other aninmals
    ·· cnthorses:
    ···· IF IN4 = 1 THEN addHoresCnt················· 'count horses
    ····· RETURN
    ······ addHorescnt:
    ······· horses = horses +1
    ········ RETURN·································· 'check other animals





    Post Edited (truckwiz) : 10/26/2006 7:32:53 PM GMT
  • [Deleted User][Deleted User] Posts: 0
    edited 2006-10-26 18:24
    dave , does that look any better
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-10-26 19:35
    The simple fix is as attached -- you add a 'bit' variable, that says "I'm seeing a Dog" (or other animal). You increment "dog count" only the FIRST time you 'see' a dog -- then as long as you continue to 'see' a dog, don't increment the count.

    And when you no longer 'see' a dog, set the 'SeeDog' variable to zero, so the NEXT time you see a dog, you'll increment the count again.
  • allanlane5allanlane5 Posts: 3,815
    edited 2006-10-26 19:42
    Now, this does assume that once you 'see' a dog, you'll continue to 'see' that dog until it makes it outside. If this is not true, you may need to 'debounce' the 'I see a dog' pin signal. This means you require that signal to be 'on' for a while before you declare that you "SeeDog", and then require it to be off for some time period before you declare "SeeDog" is zero.
  • [Deleted User][Deleted User] Posts: 0
    edited 2006-10-27 00:38
    WOW !!!! , pluged the code in my protes vsm works aaaaaaawsome !!!!!!!!

    THANK YOU very much,

    Brian


    ok next problem, as you can see from my attachments this program is not for my farm animals , the code does not reflect the fact that my next step is to hook up a touch screen , can i use the stamp plc's sin & sout for this or do in need to use 2 in & out pins ?


    I found the code serin16 & serout16 , but where does tx & rx hook to· ?

    Post Edited (truckwiz) : 10/27/2006 3:01:48 PM GMT
    2160 x 1440 - 842K
    2160 x 1440 - 886K
Sign In or Register to comment.