Python3, GPIO, Minidock & LED Blink



  • Just tested the GPIO using the minidock to blink an LED (with an integrated resistor on the anode). Used the code compiled by @Frederick Blais

    https://gist.githubusercontent.com/anonymous/b58c91419c0c5c7b2c69/raw/9be1c07e849db4c8ab61f4641b071e9b15e59951/leds.py

    Adapted it slightly to blink the LED connected to PIN 19.

    14482381935301.jpg

    14482381934290.jpg

    Here's an example of the Python script:
    (Just make sure to put the indents where they're needed as per Python standards)

    from subprocess import call
    from time import sleep
    
    RED = 19
    
    PINS = (RED)
    HI = 0
    LO = 1
    
    def state(pin, state):
        if pin:
            call(["fast-gpio", "set", str(pin), state])
        else:
            for pin in PINS:
                call(["fast-gpio", "set", str(pin), state])
    
    def off(pin=None):
        state(pin, str(LO))
    
    def on(pin=None):
        state(pin, str(HI))
    
    def rotate(delay=0.05):
        while(True):
            off(RED)
            sleep(RED)
            on(RED)
            sleep(RED)
    
    def blink(pin, delay=0.5):
        while(True):
            on(pin)
            sleep(delay)
            off(pin)
            sleep(delay)
    
    
    if __name__=="__main__":
            off()
            #rotate()
            blink(RED)
    

  • administrators

    Awesome!



Looks like your connection to Community was lost, please wait while we try to reconnect.