Skip to content

Commit 24c86d2

Browse files
committed
Merge remote-tracking branch 'adafruit/master'
2 parents 285bc7f + 56e3c81 commit 24c86d2

24 files changed

Lines changed: 7499 additions & 0 deletions
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
# Vertical Word Clock using the Adafruit Feather M4 and
2+
# the Adafruit DS3231 real-time clock FeatherWing
3+
4+
import time
5+
import board
6+
import busio as io
7+
import digitalio
8+
import adafruit_ds3231
9+
import neopixel
10+
11+
i2c = io.I2C(board.SCL, board.SDA)
12+
13+
# Create the RTC instance:
14+
rtc = adafruit_ds3231.DS3231(i2c)
15+
16+
LED13 = digitalio.DigitalInOut(board.D13)
17+
LED13.direction = digitalio.Direction.OUTPUT
18+
19+
pixel_pin = board.D5
20+
num_pixels = 21
21+
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=1.0)
22+
pixels.fill((0, 0, 0))
23+
COLOR = (0, 200, 0) # Green
24+
25+
# Bitmap values for each value. These can be OR'ed together
26+
THREE = 1
27+
EIGHT = 1<<1
28+
ELEVEN = 1<<2
29+
TWO = 1<<3
30+
SIX = 1<<4
31+
FOUR = 1<<5
32+
SEVEN = 1<<6
33+
NOON = 1<<7
34+
TEN = 1<<8
35+
ONE = 1<<9
36+
FIVE = 1<<10
37+
MIDNIGHT = 1<<11
38+
NINE = 1<<12
39+
PAST = 1<<13
40+
TO = 1<<14
41+
FIVEMIN = 1<<15
42+
QUARTER = 1<<16
43+
TENMIN = 1<<17
44+
HALF = 1<<18
45+
TWENTY = 1<<19
46+
47+
# Pass in hour and minute, return LED bitmask
48+
# pylint: disable=too-many-branches
49+
# pylint: disable=too-many-statements
50+
def writetime(the_hr, the_min):
51+
value = 0 # Start with zero, which is no words
52+
if (the_hr == 24) and (the_min == 0): # Special cases: Midnight and Noon
53+
return MIDNIGHT
54+
if (the_hr == 12) and (the_min == 0):
55+
return NOON
56+
# set minute
57+
if (the_min > 3) and (the_min < 8):
58+
value = value | FIVEMIN
59+
if (the_min > 7) and (the_min < 13):
60+
value = value | TENMIN
61+
if (the_min > 12) and (the_min < 18):
62+
value = value | QUARTER
63+
if (the_min > 17) and (the_min < 23):
64+
value = value | TWENTY
65+
if (the_min > 22) and (the_min < 28):
66+
value = value | TWENTY | FIVEMIN
67+
if (the_min > 27) and (the_min < 33):
68+
value = value | HALF
69+
if (the_min > 32) and (the_min < 38):
70+
value = value | TWENTY | FIVEMIN
71+
if (the_min > 37) and (the_min < 43):
72+
value = value | TWENTY
73+
if (the_min > 42) and (the_min < 48):
74+
value = value | QUARTER
75+
if (the_min > 47) and (the_min <= 53):
76+
value = value | TENMIN
77+
if the_min >= 54:
78+
value = value | FIVEMIN
79+
# before or after
80+
if (the_min > 3) and (the_min <= 32):
81+
value = value | PAST
82+
if the_min >= 33:
83+
the_hr = the_hr + 1 # for the TO case
84+
value = value | TO
85+
# set hour
86+
if the_hr > 12:
87+
the_hr = the_hr - 12 # Convert 24 hour format to 12 hour
88+
if the_hr == 1:
89+
value = value | ONE
90+
if the_hr == 2:
91+
value = value | TWO
92+
if the_hr == 3:
93+
value = value | THREE
94+
if the_hr == 4:
95+
value = value | FOUR
96+
if the_hr == 5:
97+
value = value | FIVE
98+
if the_hr == 6:
99+
value = value | SIX
100+
if the_hr == 7:
101+
value = value | SEVEN
102+
if the_hr == 8:
103+
value = value | EIGHT
104+
if the_hr == 9:
105+
value = value | NINE
106+
if the_hr == 10:
107+
value = value | TEN
108+
if the_hr == 11:
109+
value = value | ELEVEN
110+
if the_hr == 0:
111+
value = value | MIDNIGHT
112+
if the_hr == 12:
113+
value = value | NOON
114+
return value
115+
# end def
116+
# pylint: enable=too-many-branches
117+
# pylint: enable=too-many-statements
118+
119+
# Main loop
120+
LEDstate = 0
121+
FirstLoop = True
122+
123+
while True:
124+
t = rtc.datetime
125+
# print("The date is {} {}/{}/{}".format(days[int(t.tm_wday)],
126+
# t.tm_mday, t.tm_mon, t.tm_year))
127+
# print("The time is {}:{:02}:{:02}".format(t.tm_hour, t.tm_min, t.tm_sec))
128+
hour = t.tm_hour
129+
minute = t.tm_min
130+
second = t.tm_sec
131+
if second == 59 or FirstLoop:
132+
# print("The time is {}:{:02}".format(t.tm_hour, t.tm_min))
133+
pixels.fill((0, 0, 0)) # blank all pixels for change
134+
the_time = writetime(hour, minute)
135+
for i in range(0, 21): # Check all bits
136+
if the_time & 1 << i: # If the bit is true
137+
pixels[i+1] = COLOR # set pixel on (shift up 2 for buried one)
138+
pixels.show()
139+
if LEDstate == 0: # Flash the D13 LED every other second for activity
140+
LED13.value = True
141+
LEDstate = 1
142+
else:
143+
LED13.value = False
144+
LEDstate = 0
145+
Firstloop = False
146+
time.sleep(1) # wait a second

Playa_Bike/fiberoptic_code.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import time
2+
import board
3+
import adafruit_rgbled
4+
import digitalio
5+
6+
POWER_PIN = board.D10
7+
8+
enable = digitalio.DigitalInOut(POWER_PIN)
9+
enable.direction = digitalio.Direction.OUTPUT
10+
enable.value = True
11+
12+
# Pin the Red LED is connected to
13+
RED_LED = board.D11
14+
15+
# Pin the Green LED is connected to
16+
GREEN_LED = board.D12
17+
18+
# Pin the Blue LED is connected to
19+
BLUE_LED = board.D13
20+
21+
# Create the RGB LED object
22+
led = adafruit_rgbled.RGBLED(RED_LED, GREEN_LED, BLUE_LED)
23+
24+
# Optionally, you can also create the RGB LED object with inverted PWM
25+
# led = adafruit_rgbled.RGBLED(RED_LED, GREEN_LED, BLUE_LED, invert_pwm=True)
26+
27+
def wheel(pos):
28+
# Input a value 0 to 255 to get a color value.
29+
# The colours are a transition r - g - b - back to r.
30+
if pos < 0 or pos > 255:
31+
return 0, 0, 0
32+
if pos < 85:
33+
return int(255 - pos * 3), int(pos * 3), 0
34+
if pos < 170:
35+
pos -= 85
36+
return 0, int(255 - pos * 3), int(pos * 3)
37+
pos -= 170
38+
return int(pos * 3), 0, int(255 - (pos * 3))
39+
40+
def rainbow_cycle(wait):
41+
for i in range(255):
42+
i = (i + 1) % 256
43+
led.color = wheel(i)
44+
time.sleep(wait)
45+
46+
while True:
47+
# rainbow cycle the RGB LED
48+
rainbow_cycle(0.1)
225 KB
Binary file not shown.
225 KB
Binary file not shown.
225 KB
Binary file not shown.
225 KB
Binary file not shown.
225 KB
Binary file not shown.
225 KB
Binary file not shown.
225 KB
Binary file not shown.
225 KB
Binary file not shown.

0 commit comments

Comments
 (0)