Skip to content

Commit 4981e89

Browse files
Merge branch 'adafruit:main' into main
2 parents e45faef + 1696e6c commit 4981e89

File tree

2 files changed

+80
-0
lines changed

2 files changed

+80
-0
lines changed

LED_Noodle_Lantern/code.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# SPDX-FileCopyrightText: 2022 Noe Ruiz for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
# Adafruit nOOds lantern with "analog" (PWM) brightness control using GPIO.
4+
# Uses 6 nOOds, anode (+) to GPIO pin, cathode (-) to ground.
5+
# A current-limiting resistor (e.g. 10 Ohm) can go at either end.
6+
7+
import math
8+
import time
9+
import board
10+
import pwmio
11+
from digitalio import DigitalInOut, Direction, Pull
12+
13+
PINS = (board.SCK, board.MOSI, board.A1, board.A3, board.MISO, board.A2) # List of pins
14+
GAMMA = 2.6 # For perceptually-linear brightness
15+
16+
# Convert pin number list to PWMOut object list
17+
pin_list = [pwmio.PWMOut(pin, frequency=1000, duty_cycle=0) for pin in PINS]
18+
19+
# Button switch set up
20+
switch = DigitalInOut(board.A0)
21+
switch.direction = Direction.INPUT
22+
switch.pull = Pull.UP
23+
24+
# LED set up
25+
led = DigitalInOut(board.TX)
26+
led.direction = Direction.OUTPUT
27+
28+
while True: # Repeat forever...
29+
# If the button is pressed turn on LED n00ds
30+
if switch.value:
31+
for i, pin in enumerate(pin_list): # For each pin...
32+
# Calc sine wave, phase offset for each pin, with gamma correction.
33+
# If using red, green, blue nOOds, you'll get a cycle of hues.
34+
phase = (time.monotonic() - 2 * i / len(PINS)) * math.pi
35+
brightness = int((math.sin(phase) + 1.0) * 0.5 ** GAMMA * 65535 + 0.5)
36+
pin.duty_cycle = brightness
37+
led.value = True # Turn button LED on
38+
else: # Otherwise turn LED n00ds off
39+
for i, pin in enumerate(pin_list):
40+
pin.duty_cycle = 0
41+
led.value = False # Turn button LED off
42+
43+
time.sleep(.01)
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2+
# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries (Adapted for CLUE)
3+
#
4+
# SPDX-License-Identifier: MIT
5+
6+
import board
7+
from adafruit_pybadger import pybadger
8+
9+
pybadger.badge_background(
10+
background_color=pybadger.WHITE,
11+
rectangle_color=pybadger.PURPLE,
12+
rectangle_drop=0.2,
13+
rectangle_height=0.6,
14+
)
15+
16+
pybadger.badge_line(
17+
text="@circuitpython", color=pybadger.BLINKA_PURPLE, scale=2, padding_above=2
18+
)
19+
pybadger.badge_line(text="Blinka", color=pybadger.WHITE, scale=5, padding_above=6)
20+
pybadger.badge_line(
21+
text="CircuitPythonista", color=pybadger.WHITE, scale=2, padding_above=2
22+
)
23+
pybadger.badge_line(
24+
text="she/her", color=pybadger.BLINKA_PINK, scale=4, padding_above=7
25+
)
26+
27+
display = board.DISPLAY
28+
display.rotation = 180
29+
30+
pybadger.show_custom_badge()
31+
32+
while True:
33+
if pybadger.button.a:
34+
pybadger.show_qr_code("https://circuitpython.org")
35+
36+
if pybadger.button.b:
37+
pybadger.show_custom_badge()

0 commit comments

Comments
 (0)