Line 12... |
Line 12... |
12 |
|
12 |
|
13 |
print "Manufacturer: %s" % h.get_manufacturer_string() |
13 |
print "Manufacturer: %s" % h.get_manufacturer_string() |
14 |
print "Product: %s" % h.get_product_string() |
14 |
print "Product: %s" % h.get_product_string() |
15 |
print "Serial No: %s" % h.get_serial_number_string() |
15 |
print "Serial No: %s" % h.get_serial_number_string() |
16 |
|
16 |
|
17 |
h.write([0x02, 0xFF, 0xFF, 0x00, 0x00]) |
17 |
h.write([0x02, 0b00000010, 0x00, 0x00, 0x00]) # setup io pin direction |
18 |
sleep( 1.00 ) |
18 |
sleep( 1.00 ) |
19 |
|
19 |
|
20 |
|
20 |
|
21 |
def light(timea): |
21 |
def light(timea): |
22 |
global h |
- |
|
23 |
h.write([0x04, 0xFF, 0xFF]) |
22 |
h.write([0x04, 0xFF, 0xFF]) |
24 |
print timea |
- |
|
25 |
time.sleep(timea) |
23 |
time.sleep(timea) |
26 |
return 0 |
- |
|
27 |
|
24 |
|
28 |
def dark(timea): |
25 |
def dark(timea): |
29 |
global h |
- |
|
30 |
h.write([0x04, 0x00, 0xFF]) |
26 |
h.write([0x04, 0x00, 0xFF]) |
31 |
print timea |
- |
|
32 |
time.sleep(timea) |
27 |
time.sleep(timea) |
33 |
return 0 |
- |
|
34 |
|
28 |
|
35 |
def neon(): |
29 |
def blik(): |
36 |
light(1.15) |
- |
|
37 |
dark(0.02) |
- |
|
38 |
light(3.24) |
- |
|
39 |
dark(0.01) |
- |
|
40 |
light(1.12) |
- |
|
41 |
dark(0.2) |
- |
|
42 |
light(0.8) |
- |
|
43 |
dark(0.8) |
30 |
dark(0.8) |
44 |
light(0.45) |
- |
|
45 |
dark(0.11) |
- |
|
46 |
light(1.0) |
- |
|
47 |
dark(0.2) |
- |
|
48 |
light(3.0) |
- |
|
49 |
dark(0.1) |
- |
|
50 |
light(4.0) |
- |
|
51 |
dark(0.4) |
- |
|
52 |
light(5) |
- |
|
53 |
dark(0.04) |
- |
|
54 |
light(0.8) |
- |
|
55 |
dark(0.04) |
- |
|
56 |
light(1) |
31 |
light(1) |
57 |
dark(0.01) |
- |
|
58 |
light(2) |
- |
|
59 |
|
32 |
|
60 |
|
- |
|
61 |
def blik(): |
33 |
def check_button(): |
62 |
light(1) |
34 |
response = h.get_feature_report(0x03,2) |
63 |
dark(0.8) |
35 |
return response[1] |
64 |
|
36 |
|
65 |
def main(): |
37 |
def main(): |
66 |
init() |
38 |
init() |
- |
|
39 |
while True: |
67 |
try: |
40 |
try: |
- |
|
41 |
|
68 |
while 1: |
42 |
while True: |
- |
|
43 |
inputs = check_button() |
- |
|
44 |
print bin(inputs) |
- |
|
45 |
if not (inputs & 0b00000001) and (0b00000001): |
69 |
#blik() |
46 |
blik() |
- |
|
47 |
|
70 |
neon() |
48 |
time.sleep(0.5) |
71 |
|
49 |
|
72 |
print "Closing device" |
50 |
except IOError, ex: |
73 |
h.close() |
51 |
print ex |
74 |
|
52 |
|
75 |
except IOError, ex: |
53 |
except KeyboardInterrupt: |
- |
|
54 |
print "Closing device" |
76 |
print ex |
55 |
h.close() |
77 |
|
56 |
|
78 |
print "Done" |
57 |
print "Done" |
79 |
|
58 |
|
80 |
|
59 |
|
81 |
if __name__ == "__main__": |
60 |
if __name__ == "__main__": |
82 |
main() |
61 |
main() |