Rev Author Line No. Line
4751 jacho 1 #!/usr/bin/python
2  
3 import sys
4 import time
5 from pymlab import config
6  
7  
8 ### Script Arguments ###############################################
9  
10 if len(sys.argv) != 2:
11 sys.stderr.write("Invalid number of arguments.\n")
12 sys.stderr.write("Usage: %s PORT ADDRESS\n" % (sys.argv[0], ))
13 sys.exit(1)
14  
15 port = eval(sys.argv[1])
16 #### Sensor Configuration ###########################################
17  
18  
19 cfg = config.Config(
20 i2c = {
21 "port": port,
22 },
23 bus = [
24 {
25 "name":"gpio",
26 "type":"TCA6416A"
27 },
28 ],
29 )
30  
31  
32 cfg.initialize()
33  
34 print "I2C GPIO example for I2CIO01A MLAB module. \r\n"
35  
36 gpio = cfg.get_device("gpio")
37  
38 try:
39 gpio.config_ports(0x0000, 0x0000)
40 state = 0b1
41  
42 while True:
43 for i in range(0,7):
44 state = state << 1
45 gpio.set_ports(state, state)
46 print bin(state)
47 time.sleep(0.1)
48  
49 for i in range(0,7):
50 state = state >> 1
51 gpio.set_ports(state, state)
52 print bin(state)
53 time.sleep(0.1)
54 finally:
55 print "stop"
56