Skip to content

Instantly share code, notes, and snippets.

@thisMagpie
Last active February 4, 2016 16:23
Show Gist options
  • Select an option

  • Save thisMagpie/ed6c9f0283e490de9a9c to your computer and use it in GitHub Desktop.

Select an option

Save thisMagpie/ed6c9f0283e490de9a9c to your computer and use it in GitHub Desktop.
import webiopi
from webiopi.devices.digital import PCF8574A
mcp = PCF8574A(slave=0x38) # 0111000
GPIO = webiopi.GPIO # Assign webiopi library to GPIO object
leds = 4 # number of led outputs in total (negative logic)
for index in range(leds):
mcp.setFunction(index, GPIO.OUT) #Set pin at index as output
mcp.digitalWrite(index, GPIO.LOW) # Turn on LED at index for the first time
"""
Function to toggle logic
"""
def toggleLED():
while True: # Always run loop
for index in range(leds):
value = not mcp.digitalRead(index) # Assign opposite of current state (i.e. high or low) to value
mcp.digitalWrite(index, value) # Write assigned value to P[index] output (negative logic)
if index == 0:
webiopi.sleep(0.50) # Wait 0.5 seconds
if index == 1:
webiopi.sleep(1.0) # Wait 1 second
if index == 2:
webiopi.sleep(0.10) # Wait 0.1 seconds
if index == 3:
webiopi.sleep(0.20) # Wait 0.2 seconds
toggleLED()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment