-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathleds-rgb-test.py
47 lines (32 loc) · 1.34 KB
/
leds-rgb-test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
import time
import smbus
I2C_CHANNEL = 11
LEGACY_I2C_CHANNEL = 3
FT903_I2C_ADDR = 0x1C
print('Pi-puck RGB LEDs example')
print('Initialising I2C...')
try:
bus = smbus.SMBus(I2C_CHANNEL)
except FileNotFoundError:
bus = smbus.SMBus(LEGACY_I2C_CHANNEL)
print('Cycling LEDs...')
bus.write_byte_data(FT903_I2C_ADDR, 0x00, 0x01) # Set LED1 to red
bus.write_byte_data(FT903_I2C_ADDR, 0x01, 0x02) # Set LED2 to green
bus.write_byte_data(FT903_I2C_ADDR, 0x02, 0x04) # Set LED3 to blue
time.sleep(1)
bus.write_byte_data(FT903_I2C_ADDR, 0x00, 0x02) # Set LED1 to green
bus.write_byte_data(FT903_I2C_ADDR, 0x01, 0x04) # Set LED2 to blue
bus.write_byte_data(FT903_I2C_ADDR, 0x02, 0x01) # Set LED3 to red
time.sleep(1)
bus.write_byte_data(FT903_I2C_ADDR, 0x00, 0x04) # Set LED1 to blue
bus.write_byte_data(FT903_I2C_ADDR, 0x01, 0x01) # Set LED2 to red
bus.write_byte_data(FT903_I2C_ADDR, 0x02, 0x02) # Set LED3 to green
time.sleep(1)
bus.write_byte_data(FT903_I2C_ADDR, 0x00, 0x07) # Set LED1 to white
bus.write_byte_data(FT903_I2C_ADDR, 0x01, 0x07) # Set LED2 to white
bus.write_byte_data(FT903_I2C_ADDR, 0x02, 0x07) # Set LED3 to white
time.sleep(1)
bus.write_byte_data(FT903_I2C_ADDR, 0x00, 0x00) # Set LED1 to off
bus.write_byte_data(FT903_I2C_ADDR, 0x01, 0x00) # Set LED2 to off
bus.write_byte_data(FT903_I2C_ADDR, 0x02, 0x00) # Set LED3 to off