' ' Counting animals ' #picaxe 08m2 ' ' Pins ' symbol sen1pin=pin3 ' vstupni senzor symbol sen2pin=pin4 ' vystupni senzor symbol ledoccu=1 ' led obsazeno symbol ledfree=2 ' led volno ' ' Variables ' symbol sen1old=bit15 ' vstupni senzor predchozi stav symbol sen2old=bit14 ' vystupni senzor predchozi stav symbol sen1new=bit13 ' vstupni senzor soucasny stav symbol sen2new=bit12 ' vystupni senzor soucasny stav symbol animals=b27 ' pocet zvirat v trubce ' ' Constants ' symbol SEN1ACT=0 ' vstupni senzor aktivni uroven symbol SEN2ACT=0 ' vystupni senzor aktivni uroven symbol WTIME=100 ' doba cekani v ms ' ' Program ' Setup: pullup ON sen1old=sen1pin sen2old=sen2pin pause WTIME Main: do 'nacteme soucasny stav cidel sen1new=sen1pin sen2new=sen2pin 'testujeme nabeznou hranu vstupniho senzoru if sen1old<>SEN1ACT and sen1new=SEN1ACT then inc animals endif 'testujeme nabeznou hranu vystupniho senzoru if sen2old<>SEN1ACT and sen2new=SEN1ACT then if animals>0 then dec animals endif endif 'zkopirujeme soucasny stav cidel do promennych predchoziho stavu sen1old=sen1new sen2old=sen2new 'rozsvitime LED podle poctu zvirat v trubce if animals>0 then high ledoccu low ledfree else low ledoccu high ledfree endif 'prodleva mezi testovanim pause WTIME loop