Skip to content

Commit dd5d687

Browse files
authored
Merge branch 'master' into pyportal-wakeup-light
2 parents 8e9a9f0 + 75dafd1 commit dd5d687

13 files changed

Lines changed: 48 additions & 156 deletions

File tree

Lines changed: 21 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
import glob
22
import time
33
import datetime
4-
from Adafruit_LED_Backpack import SevenSegment
4+
from adafruit_ht16k33 import segments
55
import board
6+
import busio
67
import digitalio
78

89
switch_pin = digitalio.DigitalInOut(board.D18)
910
switch_pin.direction = digitalio.Direction.INPUT
1011
switch_pin.pull = digitalio.Pull.UP
1112

12-
segment = SevenSegment.SevenSegment(address=0x70)
13-
# Initialize the display. Must be called once before using the display.
14-
segment.begin()
13+
# Create the I2C interface.
14+
i2c = busio.I2C(board.SCL, board.SDA)
15+
16+
# Create the LED segment class.
17+
# This creates a 7 segment 4 character display:
18+
display = segments.Seg7x4(i2c)
1519

1620
base_dir = '/sys/bus/w1/devices/'
1721
device_folder = glob.glob(base_dir + '28*')[0]
@@ -36,50 +40,29 @@ def read_temp():
3640
return temp_c, temp_f
3741

3842
def display_temp():
39-
segment.set_colon(False)
40-
temp = int(read_temp()[1]) # F
41-
# temp = int(read_temp()[0]) # C
42-
sign = (temp < 0)
43-
temp = abs(temp)
44-
digit_1 = int(temp % 10)
45-
temp = temp / 10
46-
digit_2 = int(temp % 10)
47-
temp = temp / 10
48-
digit_3 = int(temp % 10)
49-
if sign :
50-
segment.set_digit_raw(0, 0x40) # - sign
51-
if digit_3 > 0 :
52-
segment.set_digit(0, digit_3) # Hundreds
53-
else:
54-
segment.set_digit_raw(0, 0)
55-
if digit_2 > 0 :
56-
segment.set_digit(1, digit_2) # Tens
57-
else:
58-
segment.set_digit_raw(1, 0)
59-
segment.set_digit(2, digit_1) # Ones
60-
segment.set_digit_raw(3, 0x71) #F # Temp units letter
61-
# segment.set_digit_raw(3, 0x39) #C
43+
temp = read_temp()[1] # F
44+
# temp = read_temp()[0] # C
45+
display.print(int(temp))
6246

6347
def display_time():
6448
now = datetime.datetime.now()
6549
hour = now.hour
6650
minute = now.minute
6751
second = now.second
68-
# Set hours
69-
segment.set_digit(0, int(hour / 10)) # Tens
70-
segment.set_digit(1, hour % 10) # Ones
71-
# Set minutes
72-
segment.set_digit(2, int(minute / 10)) # Tens
73-
segment.set_digit(3, minute % 10) # Ones
74-
# Toggle colon
75-
segment.set_colon(second % 2) # Toggle colon at 1Hz
52+
clock = int('%i%i' % (hour,minute)) # concat hour + minute
53+
display.print(clock)
7654

55+
# Toggle colon when displaying time
56+
if second % 2:
57+
display.print(':') # Enable colon every other second
58+
else:
59+
display.print(';') # Turn off colon
60+
61+
display.fill(0)
7762

7863
while True:
79-
segment.clear()
8064
if not switch_pin.value:
8165
display_temp()
82-
else :
66+
else:
8367
display_time()
84-
segment.write_display()
8568
time.sleep(0.5)

Neopixel_Badge_Lanyard/code.py

Lines changed: 0 additions & 108 deletions
This file was deleted.

Propmaker_Master_Sword/code.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"""
1111

1212
import time
13+
import random
1314
import digitalio
1415
import audioio
1516
import busio
@@ -19,24 +20,24 @@
1920

2021
# CUSTOMISE COLORS HERE:
2122
COLOR = (0, 120, 120) # Default idle is light blue
22-
ALT_COLOR = (255, 255, 255) # hit color is bright white
23+
ALT_COLOR = (255, 50, 0) # hit color is orange
2324

2425
# CUSTOMISE IDLE PULSE SPEED HERE: 0 is fast, above 0 slows down
25-
IDLE_PULSE_SPEED = 0.05 # Default is 0.1 seconds
26-
SWING_BLAST_SPEED = 0.01
26+
IDLE_PULSE_SPEED = 0 # Default is 0 seconds
27+
SWING_BLAST_SPEED = 0.007
2728

2829
# CUSTOMISE BRIGHTNESS HERE: must be a number between 0 and 1
29-
IDLE_PULSE_BRIGHTNESS_MIN = 0.3 # Default minimum idle pulse brightness
30-
IDLE_PULSE_BRIGHTNESS_MAX = 0.6 # Default maximum idle pulse brightness
30+
IDLE_PULSE_BRIGHTNESS_MIN = 0.2 # Default minimum idle pulse brightness
31+
IDLE_PULSE_BRIGHTNESS_MAX = 1 # Default maximum idle pulse brightness
3132

3233
# CUSTOMISE SENSITIVITY HERE: smaller numbers = more sensitive to motion
33-
HIT_THRESHOLD = 500
34-
SWING_THRESHOLD = 125
34+
HIT_THRESHOLD = 250
35+
SWING_THRESHOLD = 150
3536

3637
# Set to the length in seconds of the "on.wav" file
3738
POWER_ON_SOUND_DURATION = 1.7
3839

39-
NUM_PIXELS = 30 # Number of pixels used in project
40+
NUM_PIXELS = 83 # Number of pixels used in project
4041
NEOPIXEL_PIN = board.D5
4142
POWER_PIN = board.D10
4243

@@ -120,6 +121,22 @@ def mix(color_1, color_2, weight_2):
120121
int(color_1[1] * weight_1 + color_2[1] * weight_2),
121122
int(color_1[2] * weight_1 + color_2[2] * weight_2))
122123

124+
# List of swing wav files without the .wav in the name for use with play_wav()
125+
swing_sounds = [
126+
'swing1',
127+
'swing2',
128+
'swing3',
129+
'swing4',
130+
]
131+
132+
# List of hit wav files without the .wav in the name for use with play_wav()
133+
hit_sounds = [
134+
'hit1',
135+
'hit2',
136+
'hit3',
137+
'hit4',
138+
]
139+
123140

124141
mode = 0 # Initial mode = OFF
125142

@@ -150,12 +167,12 @@ def mix(color_1, color_2, weight_2):
150167
# comparing thresholds...use squared values instead.)
151168
if accel_total > HIT_THRESHOLD: # Large acceleration = HIT
152169
TRIGGER_TIME = time.monotonic() # Save initial time of hit
153-
play_wav('hit') # Start playing 'hit' sound
170+
play_wav(random.choice(hit_sounds)) # Start playing 'hit' sound
154171
COLOR_ACTIVE = COLOR_HIT # Set color to fade from
155172
mode = 3 # HIT mode
156173
elif mode == 1 and accel_total > SWING_THRESHOLD: # Mild = SWING
157174
TRIGGER_TIME = time.monotonic() # Save initial time of swing
158-
play_wav('swing') # Start playing 'swing' sound
175+
play_wav(random.choice(swing_sounds)) # Randomly choose from available swing sounds
159176
# make a larson scanner animation_time
160177
strip_backup = strip[0:-1]
161178
for p in range(-1, len(strip)):
-94.8 KB
Binary file not shown.
31.6 KB
Binary file not shown.
33 KB
Binary file not shown.
40.2 KB
Binary file not shown.
38.8 KB
Binary file not shown.
-34.5 KB
Binary file not shown.
38.8 KB
Binary file not shown.

0 commit comments

Comments
 (0)