This is a program I came up for a device meant as a sort of gift for my former boss. It spits out a user defined number of gumballs (he's the R&D manager at a confectionary company). Eclectic pointed out in another post (http://www.picaxeforum.co.uk/showthread.php?p=66396#post66396) a few oversights that I made with regards to the original program. One concern of mine is the counting of the gumballs after they've been dispensed.
After determining how many gumballs have to be dispensed, the motor is turned on. As gumballs pass out a shoot, the voltage change is recorded by a light dependent resitor and the number of times this occurs is compared to the the number of gumballs that should be dispensed. Once the two values are equal, the motor shuts off. Does anyone think this is an appropriate method? I haven't been able to come up with anything better, so some input would be great.
Thanks
-mack
After determining how many gumballs have to be dispensed, the motor is turned on. As gumballs pass out a shoot, the voltage change is recorded by a light dependent resitor and the number of times this occurs is compared to the the number of gumballs that should be dispensed. Once the two values are equal, the motor shuts off. Does anyone think this is an appropriate method? I haven't been able to come up with anything better, so some input would be great.
Thanks
-mack
Code:
'08M gumball/jawbreaker dispenser program
symbol trimpot = 1 'leg 6
symbol trimpot_value = b1
symbol pbutton = pin3 'leg 4
symbol supposed_to_dispense = b2
symbol pressed = 1
symbol count_LDR = b3
symbol dispensed = b4
symbol LDR_pin = 4 'leg3
symbol LDR_value = b5
pwmout 2 off 'make sure the motor isn't on yet
read_trimpot:
readadc trimpot, trimpot_value 'read trimpot and put value into memory
goto button_press
button_press:
if pbutton = 0 then to_b_dispsensed 'if button is pressed goto main and dispensed gumballs/jawbreakers
goto read_trimpot 'if button is not pressed read trimpot and check for button press
to_b_dispsensed:
if trimpot_value < 26 then
let supposed_to_dispense = 20
goto main
endif
if trimpot_value < 51 then
let supposed_to_dispense = 40
goto main
endif
if trimpot_value < 77 then
let supposed_to_dispense = 60
goto main
endif
if trimpot_value < 102 then
let supposed_to_dispense = 80
goto main
endif
if trimpot_value < 128 then
let supposed_to_dispense = 100
goto main
endif
if trimpot_value < 153 then
let supposed_to_dispense = 120
goto main
endif
if trimpot_value < 179 then
let supposed_to_dispense = 140
goto main
endif
if trimpot_value < 204 then
let supposed_to_dispense = 160
goto main
endif
if trimpot_value < 230 then
let supposed_to_dispense = 180
goto main
endif
if trimpot_value < 255 then
let supposed_to_dispense = 200
goto main
endif
main:
pwmout 2,99,4 'turn motor on
readadc LDR_pin, LDR_value 'checks if gumball has passed and start comparing
if LDR_value > 50 then let count_LDR = count_LDR + 1
goto count_pballs
else
goto main
endif
count_pballs:
let dispensed = count_LDR
if dispensed < supposed_to_dispense then goto main
pwmout 2 off
Last edited: