def shake(duration=2.): #duration is in seconds #we don't use pwm gpio.digital_write(shaker_pin_bcm, 1) sleep(duration) gpio.digital_write(shaker_pin_bcm, 0)
def pump(duration=2.): #duration is in seconds print("Pump start") #we don't use pwm gpio.digital_write(pump_pin_bcm, 1) sleep(duration) gpio.digital_write(pump_pin_bcm, 0) print("pump stop")
def send_command(self, command) -> None: """Send command to epaper IC""" if self.sleeping: self.reset() self.sleeping = False gpio.digital_write(self.dc_pin, 0) gpio.epaper_write(command)
def grobot_time_elapsed(): ''' called when the time is over to stop Grobot from moving ''' print "switching AX12 off..." for name, _ in AX12_list: getattr(robot, name).turn(0) getattr(robot, name).set_torque(0) gpio.digital_write(pump_pin_bcm, 0) robot.emergency_stop()
def send_data(self, data: Union[int, Tuple[bytes], List[bytes]]) -> None: if self.sleeping: self.reset() self.sleeping = False gpio.digital_write(self.dc_pin, 1) if isinstance(data, (tuple, list)): gpio.epaper_transfer_data(data) else: gpio.epaper_write(data)
def gpio_demo() : """import gpio print "gpio imported" gpio.pin_mode(PE7, gpio.OUTPUT) print "looping" while True: gpio.digital_write(PE7, gpio.HIGH) gpio.digital_write(PE7, gpio.LOW)""" from gpio import pin_mode, digital_write, OUTPUT, INPUT, HIGH, LOW print "gpio imported" pin_mode("E", 7, OUTPUT) print "looping" while True: digital_write(PE7, HIGH) digital_write(PE7, LOW)
def __init__(self, valve_number, start_time, length): self.start_time = start_time self.length = length self.valve_number = valve_number self.done = False if valve_number == 0: self.valve_gpio = 125 elif valve_number == 1: self.valve_gpio = 126 elif valve_number == 2: self.valve_gpio = 127 elif valve_number == 3: self.valve_gpio = 129 # Why? gpio.pin_mode(self.valve_gpio, 'high', True) gpio.digital_write(self.valve_gpio, 0)
def check_timing(self): now = datetime.datetime.now() start = datetime.datetime.combine(datetime.date.today(), datetime.datetime.min.time()) + datetime.timedelta(seconds=self.start_time) end = datetime.datetime.combine(datetime.date.today(), datetime.datetime.min.time()) + datetime.timedelta(seconds=self.start_time + self.length) if (now > start and now < end): # Turn on valve gpio.digital_write(self.valve_gpio, 1) print start print end print 'ON' if now > end: # Turn off valve gpio.digital_write(self.valve_gpio, 0) print 'OFF' self.done = True
def reset(self) -> None: """Module reset""" gpio.digital_write(self.reset_pin, 1) gpio.delay_ms(200) gpio.digital_write(self.reset_pin, 0) gpio.delay_ms(10) gpio.digital_write(self.reset_pin, 1) gpio.delay_ms(200)
def dg_write(self, s_pin, value): """ """ gpio.digital_write(s_pin, value)
gpio.init() 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)
import gpio import time gpio.pin_mode(125, 'high', True) gpio.pin_mode(126, 'high', True) gpio.pin_mode(127, 'high', True) gpio.pin_mode(129, 'high', True) gpio.digital_write(125, 1) time.sleep(0.5) gpio.digital_write(126, 1) time.sleep(0.5) gpio.digital_write(127, 1) time.sleep(0.5) gpio.digital_write(129, 1) time.sleep(0.5) gpio.digital_write(125, 0) time.sleep(0.5) gpio.digital_write(126, 0) time.sleep(0.5) gpio.digital_write(127, 0) time.sleep(0.5) gpio.digital_write(129, 0)