from machine import Pin
import time
time.sleep(0.1) # Wait for USB to become ready
print("Hello, Pi Pico!")
#################################################
# User Settings
pusherType = "solenoid"
# pusherType = "motor"
# Pin Mappings
FIRE_BUTTON_PIN = 4
REV_BUTTON_PIN = 5
FIRE_MOTOR_SWITCH_PIN = 12
FIRE_LED_PIN = 6
REV_LED_PIN = 7
SINGLE_SHOT_PIN = 8
TRIPLE_SHOT_PIN = 9
FULL_AUTO_PIN = 10
ADMIN_MODE = 11
# ASSIGN PINS
revButton = Pin(REV_BUTTON_PIN, Pin.IN, Pin.PULL_UP)
fireButton = Pin(FIRE_BUTTON_PIN , Pin.IN, Pin.PULL_UP)
fireButton = Pin(FIRE_MOTOR_SWITCH_PIN , Pin.IN, Pin.PULL_UP)
revLED = Pin(REV_LED_PIN, Pin.OUT)
fireLED = Pin(FIRE_LED_PIN, Pin.OUT)
mode1 = Pin(SINGLE_SHOT_PIN , Pin.IN, Pin.PULL_UP)
mode2 = Pin(TRIPLE_SHOT_PIN , Pin.IN, Pin.PULL_UP)
mode3 = Pin(FULL_AUTO_PIN , Pin.IN, Pin.PULL_UP)
mode4 = Pin(ADMIN_MODE , Pin.IN, Pin.PULL_UP)
# set initial state
revLED.value(0)
fireLED.value(0)
pinInValueTrue = 0
pinInValueFalse = 1
pinOutValueTrue = 1
pinOutValueFalse = 0
single = 1
burst = 3
full = 100
def wait_pin_change(pin):
# wait for pin to change value
# it needs to be stable for a continuous 20ms
cur_value = pin.value()
active = 0
change = False
while active < 20:
if pin.value() != cur_value:
active += 1
time.sleep_ms(1)
change = True
print("changed")
else:
active = 20
# print("Nothing")
return cur_value, change
def fireSequence(firemode, pusherType):
if revButton.value() == pinInValueFalse and mode4.value() == pinInValueFalse:
print('no rev')
return
count = 0
if pusherType == "solenoid":
while wait_pin_change(fireButton) == pinInValueTrue and count < firemode:
fireLED(pinOutValueTrue)
time.sleep_ms(100)
print('go')
count += 1
fireLED(pinOutValueFalse)
time.sleep_ms(300)
elif pusherType == "motor":
print('motorswitch in here')
# class button_class():
# pinValue = 1
# previousPinValue = 1
# def pinReturnValue(self)
# return self.pinValue
# revButtonChange = button_class(revButton);
# def pined(pin):
# activeValue = pin.value()
# active = 0
# return (pin.value())
runfireTriggerOnce = True
# Main Loop
while True:
# print (mode4.value())
# print (mode3.value())
shots = 0
if mode1.value() == pinInValueTrue:
shots = single
elif mode2.value() == pinInValueTrue:
shots = burst
elif mode3.value() == pinInValueTrue:
shots = full
# print("FIRE", wait_pin_change(fireButton))
if wait_pin_change(revButton) == pinInValueTrue:
revLED(pinOutValueTrue)
elif revButton.value() == pinInValueFalse:
revLED(pinOutValueFalse)
if wait_pin_change(fireButton) == pinInValueTrue:
if runfireTriggerOnce:
fireSequence(shots, pusherType)
runfireTriggerOnce = False
else:
runfireTriggerOnce = True
# time.sleep_ms(500)