
# www.tctec.net
#
# Example for controlling the Super4 USB Relay module
# 20-Sep-2015
#
# Remember to run the python script as super user (sudo python super4demo)
#
# Discover the name of your board with 
#    sudo python -m pylibftdi.examples.list_devices
#
#

import time
import threading
import pylibftdi
from pylibftdi import BitBangDevice

# change this to the name of your device
boardName = "FTYM703N"


print("Super4 Test 3")

super4 =  BitBangDevice(boardName)

def setupSuper4():
    
    super4.port |= 0x0F
    super4.direction = 0x0F 
    super4.port |= 0x0F
    super4.bits = 0x01;
    



# do this every 2 seconds by re-setting a timer inside the function
def doOnTimer():
    threading.Timer(2.0, doOnTimer).start()    
    bits = super4.bits
    
    # shift the bit left by 1
    bits <<= 1
    if (bits > 0x0F):
        bits = 0x01;    
    
    super4.port |= 0x0F  # turn all relays off (1 = off)
    time.sleep(0.1)
    super4.port &= ~bits # turn on the relay, (0 = on)    
    
    super4.bits = bits


setupSuper4();
doOnTimer()


while (1==1):
    pass
    
