示例#1
0
 def wait_until_idle(self) -> None:
     timeout = 0
     while gpio.digital_read(self.busy_pin) == 0:  # 0: busy, 1: idle
         gpio.delay_ms(100)
         timeout += 1
         if timeout >= 100:
             LOG.debug(
                 "EPAPER: busy signal did not deactivate/epaper not responding in 10 sec"
             )
             timeout = 0
示例#2
0
def is_obstacle_backwards():
    for sensor in rear_sensors_pin_list_bcm:
        if gpio.digital_read(sensor) == 1:
            return True
    return False
示例#3
0
def get_team_color():
    if gpio.digital_read(color_button_pin_bcm) == 1:
        return "orange"
    else:
        return "green"
示例#4
0
def wait_for_catapult_up():
    while gpio.digital_read(catapult_button_pin_bcm) == 0:
        sleep(CATAPULT_MEASUREMENT_PERIOD)
示例#5
0
pin_index = gpio.gpio_index_of_wpi_pin(5)
print "GPIO 5 corresponds to BCM index "+str(pin_index)

gpio.set_pin_mode(pin_index, gpio.OUTPUT)


def print_something(index, text):
    print "GPIO "+str(index)+" "+text

gpio.assign_callback_on_gpio_down(pin_index, lambda: print_something(pin_index, "down"))

print ""
gpio.digital_write(pin_index, 1)
time.sleep(0.5)
print "Read "+str(gpio.digital_read(pin_index))+" on pin "+str(pin_index)
gpio.digital_write(pin_index, 0)
time.sleep(0.5)
print "Read "+str(gpio.digital_read(pin_index))+" on pin "+str(pin_index)

gpio.assign_callback_on_gpio_change(pin_index, lambda: print_something(pin_index, "changed"))

print ""
gpio.digital_write(pin_index, 1)
time.sleep(0.5)
print "Read "+str(gpio.digital_read(pin_index))+" on pin "+str(pin_index)
gpio.digital_write(pin_index, 0)
time.sleep(0.5)
print "Read "+str(gpio.digital_read(pin_index))+" on pin "+str(pin_index)

gpio.assign_callback_on_gpio_change(pin_index, lambda: print_something(pin_index, "changed (one shot, disappear after beeing triggered)"), True) # the last "True" argument is for one shot callback
示例#6
0
switch_pin_bcm = 6

gpio.set_pull_up_down(  switch_pin_bcm,     gpio.PULL_UP)
gpio.set_pin_mode(      switch_pin_bcm,     gpio.INPUT)

pump_amplitude = 20

ax_shoot = AX12(121)
ax_shoot.move(100)
ax_pump = AX12(163)
ax_pump.move(-pump_amplitude)
ax_pump.set_speed(15)

turning_left = True

previous = gpio.digital_read(switch_pin_bcm)

while gpio.digital_read(switch_pin_bcm) == previous:
    sleep(1)
    
i=0
while True:
    i=i+1
    if turning_left:
        ax_pump.move(pump_amplitude)
    else:
        ax_pump.move(-pump_amplitude)
    turning_left = not turning_left
    sleep(1)
    if(i==15):
        ax_shoot.move(130)