Merge branch 'adafruit:main' into main

This commit is contained in:
Paint Your Dragon 2022-10-05 17:11:01 -07:00 committed by GitHub
commit 4981e89018
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 80 additions and 0 deletions

43
LED_Noodle_Lantern/code.py Executable file
View file

@ -0,0 +1,43 @@
# SPDX-FileCopyrightText: 2022 Noe Ruiz for Adafruit Industries
# SPDX-License-Identifier: MIT
# Adafruit nOOds lantern with "analog" (PWM) brightness control using GPIO.
# Uses 6 nOOds, anode (+) to GPIO pin, cathode (-) to ground.
# A current-limiting resistor (e.g. 10 Ohm) can go at either end.
import math
import time
import board
import pwmio
from digitalio import DigitalInOut, Direction, Pull
PINS = (board.SCK, board.MOSI, board.A1, board.A3, board.MISO, board.A2) # List of pins
GAMMA = 2.6 # For perceptually-linear brightness
# Convert pin number list to PWMOut object list
pin_list = [pwmio.PWMOut(pin, frequency=1000, duty_cycle=0) for pin in PINS]
# Button switch set up
switch = DigitalInOut(board.A0)
switch.direction = Direction.INPUT
switch.pull = Pull.UP
# LED set up
led = DigitalInOut(board.TX)
led.direction = Direction.OUTPUT
while True: # Repeat forever...
# If the button is pressed turn on LED n00ds
if switch.value:
for i, pin in enumerate(pin_list): # For each pin...
# Calc sine wave, phase offset for each pin, with gamma correction.
# If using red, green, blue nOOds, you'll get a cycle of hues.
phase = (time.monotonic() - 2 * i / len(PINS)) * math.pi
brightness = int((math.sin(phase) + 1.0) * 0.5 ** GAMMA * 65535 + 0.5)
pin.duty_cycle = brightness
led.value = True # Turn button LED on
else: # Otherwise turn LED n00ds off
for i, pin in enumerate(pin_list):
pin.duty_cycle = 0
led.value = False # Turn button LED off
time.sleep(.01)

View file

@ -0,0 +1,37 @@
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries (Adapted for CLUE)
#
# SPDX-License-Identifier: MIT
import board
from adafruit_pybadger import pybadger
pybadger.badge_background(
background_color=pybadger.WHITE,
rectangle_color=pybadger.PURPLE,
rectangle_drop=0.2,
rectangle_height=0.6,
)
pybadger.badge_line(
text="@circuitpython", color=pybadger.BLINKA_PURPLE, scale=2, padding_above=2
)
pybadger.badge_line(text="Blinka", color=pybadger.WHITE, scale=5, padding_above=6)
pybadger.badge_line(
text="CircuitPythonista", color=pybadger.WHITE, scale=2, padding_above=2
)
pybadger.badge_line(
text="she/her", color=pybadger.BLINKA_PINK, scale=4, padding_above=7
)
display = board.DISPLAY
display.rotation = 180
pybadger.show_custom_badge()
while True:
if pybadger.button.a:
pybadger.show_qr_code("https://circuitpython.org")
if pybadger.button.b:
pybadger.show_custom_badge()