'08M program
symbol pbutton = pin3
symbol pressed = 0
symbol trimpot_pin = 1
symbol trimpot_value = b1 'put the trimpot value into memory address b1
symbol LDR_pin = 4
symbol LDR_value = b2 'put the LDR value into memory address b2
symbol dispensed = b5 'count the number of times pballs fall into memory address b3
symbol supposed_to_dispense = b4
read_trimpot:
readadc trimpot_pin, trimpot_value 'read the value from the trimpot and put it into variable "trimpot_value"
goto button_press 'check if user has pressed button to start dispensing pballs
button_press:
if pbutton = pressed then main 'checks to see if the switched has been pressed
goto read_trimpot 'if button isn't pressed, checks value of pot to see if it's changed then checks if button has been pressed
main:
if trimpot_value < 2 then dispense_zero'if knob is turned to off, no pballs are dispensed and program goes back to check the trimpot
pwmout 2,150,150
goto check_pballs_to_be_dispensed
check_pballs_to_be_dispensed:
if trimpot_value < 26 then
let supposed_to_dispense = 20
goto read_LDR
endif
if trimpot_value < 51 then
let supposed_to_dispense = 40
goto read_LDR
endif
if trimpot_value < 77 then
let supposed_to_dispense = 60
goto read_LDR
endif
if trimpot_value < 102 then
let supposed_to_dispense = 80
goto read_LDR
endif
if trimpot_value < 128 then
let supposed_to_dispense = 100
goto read_LDR
endif
if trimpot_value < 153 then
let supposed_to_dispense = 120
goto read_LDR
endif
if trimpot_value < 179 then
let supposed_to_dispense = 140
goto read_LDR
endif
if trimpot_value < 204 then
let supposed_to_dispense = 160
goto read_LDR
endif
if trimpot_value < 230 then
let supposed_to_dispense = 180
goto read_LDR
endif
if trimpot_value < 255 then
let supposed_to_dispense = 200
goto read_LDR
endif
read_LDR:
readadc LDR_pin, LDR_value 'reads value into LDR_value
if LDR_value>50 then count_pballs
count_pballs:
let dispensed = dispensed + 1
if dispensed < supposed_to_dispense then goto read_LDR
pwmout 2,0,0
dispense_zero:
pwmout 2,0,0
goto read_trimpot