-
Notifications
You must be signed in to change notification settings - Fork 0
/
CC03.py
63 lines (50 loc) · 1.48 KB
/
CC03.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# Imports
import time
import sys
import busio
import digitalio
from board import *
class myI2C:
def __init__(self):
self.i2c = busio.I2C(SCL, SDA)
def scan(self):
print("Scanning xBus...", end="")
self.i2c.try_lock()
devices = self.i2c.scan()
self.i2c.unlock()
if len(devices) > 0:
print("found:", len(devices), "xChip(s)", end="")
for device in devices:
print(",", hex(device), end="")
else:
print("no xChips found!", end="")
print()
class myLEDs:
rgb = 0
def __init__(self):
r = digitalio.DigitalInOut(RED)
r.direction = digitalio.Direction.OUTPUT
g = digitalio.DigitalInOut(GREEN)
g.direction = digitalio.Direction.OUTPUT
b = digitalio.DigitalInOut(BLUE)
b.direction = digitalio.Direction.OUTPUT
self.leds = [r, g, b]
self.pattern = [[True, False, False],
[False, True, False],
[False, False, True]]
def toggle(self):
self.rgb += 1
for led, val in zip(self.leds, self.pattern[self.rgb % 3]):
led.value = val
def allOff(self):
for led in self.leds:
led.value = False
xChip = myI2C()
LED = myLEDs()
for _ in range(10):
xChip.scan()
LED.toggle()
time.sleep(0.1)
_, mpv = sys.implementation
mpv = ".".join(map(str, mpv))
print("This ran on Python v.{}, uPython v.{},".format(sys.version, mpv))