Last active
February 11, 2016 15:03
-
-
Save thisMagpie/459c7632ac194e015280 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
SWITCH0 = 4 # Set Switch value to P4 | |
for index in range(leds): | |
mcp.setFunction(index, GPIO.OUT) #Set pin at index as output | |
mcp.digitalWrite(index, GPIO.HIGH) # Turn n LED at index | |
mcp.setFunction(SWITCH0, GPIO.IN) # Set SWITCH as input | |
""" | |
Function to toggle logic | |
""" | |
def toggleLED(): | |
while True: # Always run loop | |
mcp.portWrite(0x0F) # Set P0-P3 as high 1111 | |
if (mcp.digitalRead(SWITCH0) == GPIO.HIGH): | |
mcp.portWrite(0x0E) # Set P0 low P1-P3 as high 1110 | |
webiopi.sleep(0.5) # Wait 0.5 second | |
mcp.portWrite(0x0A) # Set P0, P2 low P1 P3 high 1010 | |
webiopi.sleep(0.3) # Wait 0.3 second | |
mcp.portWrite(0x0D) # Set P0, P2, P3 high P1 low 1101 | |
webiopi.sleep(0.5) # Wait 0.5 second | |
mcp.portWrite(0x00) # Set P0-P3 low 0000 | |
webiopi.sleep(0.4) # Wait 0.4 second | |
mcp.digitalWrite(SWITCH0, GPIO.LOW) # Write assigned value to SWITCH0 output (negative logic) | |
toggleLED() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://groups.google.com/forum/#!msg/webiopi/MUU7Pvsp29g/uXqFsO6cXo4J