Beispiel #1
0
def on(*buttons, fn=None, action=DOWN):
    global GAMEPAD

    for button in buttons:
        if button not in BUTTONS:
            if button in DIGITALIO:
                dio = DigitalInOut(button)
                dio.direction = Direction.INPUT
                dio.pull = Pull.DOWN
            elif button in TOUCHIO:
                dio = TouchIn(button)
            else:
                print("unknown button {}".format(button))
            BUTTONS.append(button)
            DIOS.append(dio)

    value = tuple(buttons)

    def wrapper(fn):
        PRESSES.append((fn, buttons, action))
        return fn

    if fn:
        return wrapper(fn)

    return wrapper
Beispiel #2
0
import neopixel
import adafruit_minimqtt.adafruit_minimqtt as MQTT
from adafruit_io.adafruit_io import IO_MQTT
from digitalio import DigitalInOut, Direction

### WiFi ###

# Get wifi details and more from a secrets.py file
try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise

RELAY = DigitalInOut(board.D10)
RELAY.direction = Direction.OUTPUT

# If you are using a board with pre-defined ESP32 Pins:
esp32_cs = DigitalInOut(board.D13)
esp32_ready = DigitalInOut(board.D11)
esp32_reset = DigitalInOut(board.D12)

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
"""Use below for Most Boards"""
status_light = neopixel.NeoPixel(board.NEOPIXEL, 1,
                                 brightness=0.2)  # Uncomment for Most Boards
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(
    esp, secrets, status_light)

Beispiel #3
0
# SPDX-FileCopyrightText: 2019 Mikey Sklar for Adafruit Industries
#
# SPDX-License-Identifier: MIT

import time
import board
from digitalio import DigitalInOut, Direction

pir_pin = board.D24
power_pin = board.D23

pir = DigitalInOut(pir_pin)
pir.direction = Direction.INPUT

power = DigitalInOut(power_pin)
power.direction = Direction.OUTPUT
power.value = False

while True:
    if pir.value:
        print("POWER ON")
        power.value = True
        time.sleep(20)
        print("POWER OFF")
        power.value = False
        time.sleep(5)
    time.sleep(1)
Beispiel #4
0
    for i in range(1, 5):
        nullingIndex = (index + i) % num_pixels
        pixels[nullingIndex] = (0, 0, 0)

    pixels.show()
    time.sleep(.1)

    if index == 0:
        color = (color + 50) % 255

    return (color, (index + 1) % num_pixels)


buttonA = DigitalInOut(board.BUTTON_A)  #button a
buttonA.direction = Direction.INPUT
buttonA.pull = Pull.DOWN
buttonB = DigitalInOut(board.BUTTON_B)  # button b
buttonB.direction = Direction.INPUT
buttonB.pull = Pull.DOWN

startRainbowPassIn = 0
startFlashColor = (0, 0)
startMicrophonePeak = 0

curState = 0
numStates = 4
rainbowPassIn = startRainbowPassIn
flashColor = startFlashColor
microphonePeak = startMicrophonePeak
Beispiel #5
0
# importing necessary libraries
import board
#import neopixel
import time
from digitalio import DigitalInOut, Direction, Pull
from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface

from lcd.lcd import CursorMode

# defining both button_alt, button_ud, and button_red as DigitalInOut objects (as buttons
# that increase/decrease value, change modifier, and reset mod and num to 1 and 0 respectively)
button_alt = DigitalInOut(board.D6)
button_alt.direction = Direction.INPUT
button_alt.pull = Pull.UP

button_ud = DigitalInOut(board.D5)
button_ud.direction = Direction.INPUT
button_ud.pull = Pull.UP

button_res = DigitalInOut(board.D4)
button_res.direction = Direction.INPUT
button_res.pull = Pull.UP

# defining lcd as an LCD object
lcd = LCD(I2CPCF8574Interface(0x27), num_rows=2, num_cols=16)

# list that the mod button will cycle through
mods = [1, 2, 5, 10, -1, -2, -5, -10]

# number that is being increased/decreased
Beispiel #6
0
import board
import busio
import pwmio
from digitalio import DigitalInOut, Direction
from adafruit_bluefruitspi import BluefruitSPI
import adafruit_lis3dh

ADVERT_NAME = b'BlinkaNeoLamp'

# RGB LED on D11, 12, 13, we're using a Prop Maker wing
red_led = pwmio.PWMOut(board.D11, frequency=50000, duty_cycle=0)
green_led = pwmio.PWMOut(board.D12, frequency=50000, duty_cycle=0)
blue_led = pwmio.PWMOut(board.D13, frequency=50000, duty_cycle=0)
# Prop maker wing has a power pin for the LED!
power_pin = DigitalInOut(board.D10)
power_pin.direction = Direction.OUTPUT
power_pin.value = True

spi_bus = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
cs = DigitalInOut(board.D8)
irq = DigitalInOut(board.D7)
rst = DigitalInOut(board.D4)
bluefruit = BluefruitSPI(spi_bus, cs, irq, rst, debug=False)

i2c = busio.I2C(board.SCL, board.SDA)
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c)


def init_bluefruit():
    # Initialize the device and perform a factory reset
    print("Initializing the Bluefruit LE SPI Friend module")
Beispiel #7
0
CELL_RETRIES=12 # one second per try

ec_5_in = AnalogIn(board.A0)
vbatt_in = AnalogIn(board.A5)

uart = busio.UART(board.TX, board.RX, baudrate=9600)

# lora radio
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
cs = DigitalInOut(board.RFM9X_CS)
reset = DigitalInOut(board.RFM9X_RST)
rfm9x = adafruit_rfm9x.RFM9x(spi, cs, reset, 915.0)

# led
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT

# done
done = DigitalInOut(board.D10)
done.direction = Direction.OUTPUT

# roaming_switch
roam_switch = DigitalInOut(board.D12)
roam_switch.direction = Direction.INPUT
roam_switch.pull=Pull.UP

# default values if probe doesn't work

temp=30
ec_5=20
Beispiel #8
0
# External constants

DOWN = 1
UP = 2
PROPOGATE = object()

# Internal constants

DIGITALIO = [board.BUTTON_A, board.BUTTON_B]
TOUCHIO = [board.A1, board.A2, board.A3, board.A4, board.A5, board.A6, board.A7]
SAMPLERATE = 8000  # recommended

AUDIO = AudioOut(board.A0)
SPEAKER = DigitalInOut(board.SPEAKER_ENABLE)
SPEAKER.direction = Direction.OUTPUT

# Internal state

RUNNING = True
INTERVALS = {}
TIMERS = {}
BUTTONS = []
DIOS = []
PRESSES = []


def tick(fn):
    INTERVALS[fn] = (0, 0)
    return fn
Beispiel #9
0
# CircuitPython IO demo #1 - General Purpose I/O

import time
from digitalio import DigitalInOut, Direction, Pull
import board

led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT

switch = DigitalInOut(board.D2)  # For Gemma M0, Trinket M0, Metro M0 Express, ItsyBitsy M0 Express
# switch = DigitalInOut(board.D5)  # For Feather M0 Express
# switch = DigitalInOut(board.D7)  # For Circuit Playground Express
switch.direction = Direction.INPUT
switch.pull = Pull.UP


while True:
    # We could also just do "led.value = not switch.value"!
    if switch.value:
        led.value = False
    else:
        led.value = True

    time.sleep(0.01)  # debounce delay
Beispiel #10
0
    [0b0000, 0b0110, 0b1001, 0b1001, 0b0001, 0b0010, 0b0100, 0b1111, 0b0000,],
    [0b0000, 0b0110, 0b1001, 0b0001, 0b0011, 0b0001, 0b1001, 0b0110, 0b0000,],
    [0b0000, 0b0011, 0b0101, 0b1001, 0b1111, 0b0001, 0b0001, 0b0001, 0b0000,],
    [0b0000, 0b1111, 0b1000, 0b1000, 0b1110, 0b0001, 0b0001, 0b1110, 0b0000,],
    [0b0000, 0b0110, 0b1001, 0b1000, 0b0110, 0b1001, 0b1001, 0b0110, 0b0000,],
    [0b0000, 0b1111, 0b0001, 0b0001, 0b0010, 0b0100, 0b0100, 0b1000, 0b0000,],
    [0b0000, 0b0110, 0b1001, 0b1001, 0b0110, 0b1001, 0b1001, 0b0110, 0b0000,],
    [0b0000, 0b0110, 0b1001, 0b1001, 0b0110, 0b0001, 0b1001, 0b0110, 0b0000,],
]

# configure I2C
i2c = busio.I2C(board.SCL, board.SDA)

# turn on LED drivers
sdb = DigitalInOut(board.SDB)
sdb.direction = Direction.OUTPUT
sdb.value = True

# set up the two LED drivers
display = adafruit_is31fl3731.Matrix(i2c, address=0x74)
display2 = adafruit_is31fl3731.Matrix(i2c, address=0x77)


btnA = DigitalInOut(board.BTNA)
btnA.pull = Pull.UP
btnB = DigitalInOut(board.BTNB)
btnB.pull = Pull.UP
btnX = DigitalInOut(board.BTNX)
btnX.pull = Pull.UP
btnY = DigitalInOut(board.BTNY)
btnY.pull = Pull.UP
colors = [PINK, RED, ORANGE, YELLOW, GREEN, BLUE, PURPLE, TEAL, MAGENTA, CYAN]
current_colors = []

# Define sounds the keypad makes
tones = (440, 220, 245, 330, 440)  # Initial tones while scrambling
press_tone = 660  # This tone is used when each key is pressed

# Initial key values - this list will be scrambled by the scramble function
key_values = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

# Define the STEMMA QT I2C line SDA to be a digital output (nonstandard use)
# SDA will be used as a digital pin to trigger a transistor to
# axctivate a solenoid which will unlock, like a door
solenoid = DigitalInOut(board.SDA)
solenoid.direction = Direction.OUTPUT

# FUNCTIONS ------------------


def keys_clear():  # Set display in the Start mode, key LEDs off
    for i in range(12):
        macropad.pixels[i] = 0x000000
        group[i].text = " "
    macropad.pixels.show()
    group[9].text = "START"
    macropad.display.show(group)
    macropad.display.refresh()


def scramble():  # Scramble values of the keys and display on screen
Beispiel #12
0
def light_up_rgb(color, brightness_level):
    if color == "green":
        pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=brightness_level)
        for r in range(256):
            pixels.fill((r,255,0))
            time.sleep(0.5)

    elif color == "blue":
        pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=brightness_level)
        pixels.fill((0,255,255))
    time.sleep(1)
    pixels.fill((0,0,0))


button_a = DigitalInOut(board.BUTTON_A)
button_a.direction = Direction.INPUT
button_a.pull = Pull.DOWN

button_b = DigitalInOut(board.BUTTON_B)
button_b.direction = Direction.INPUT
button_b.pull = Pull.DOWN

slide_switch = DigitalInOut(board.SLIDE_SWITCH)
slide_switch.direction = Direction.INPUT
slide_switch.pull = Pull.UP



while True:
    if slide_switch.value == True:
        b_level = 0.5
Beispiel #13
0
import board
import busio
from digitalio import DigitalInOut, Direction, Pull
from PIL import Image, ImageDraw
import adafruit_ssd1306

# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)
# Create the SSD1306 OLED class.
disp = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c)


# Input pins:
button_A = DigitalInOut(board.D5)
button_A.direction = Direction.INPUT
button_A.pull = Pull.UP

button_B = DigitalInOut(board.D6)
button_B.direction = Direction.INPUT
button_B.pull = Pull.UP

button_L = DigitalInOut(board.D27)
button_L.direction = Direction.INPUT
button_L.pull = Pull.UP

button_R = DigitalInOut(board.D23)
button_R.direction = Direction.INPUT
button_R.pull = Pull.UP

button_U = DigitalInOut(board.D17)
Beispiel #14
0
led1_pin = board.GP13
led2_pin = board.GP14
led3_pin = board.GP15
led4_pin = board.GP16
led5_pin = board.GP17
led6_pin = board.GP18
led7_pin = board.GP19
led8_pin = board.GP20
led9_pin = board.GP21
led10_pin = board.GP22
led11_pin = board.GP26
led12_pin = board.GP27

# Setup all Buttons as Inputs with PullUps
btn1 = DigitalInOut(btn1_Pin)
btn1.direction = Direction.INPUT
btn1.pull = Pull.UP

btn2 = DigitalInOut(btn2_Pin)
btn2.direction = Direction.INPUT
btn2.pull = Pull.UP

btn3 = DigitalInOut(btn3_Pin)
btn3.direction = Direction.INPUT
btn3.pull = Pull.UP

btn4 = DigitalInOut(btn4_Pin)
btn4.direction = Direction.INPUT
btn4.pull = Pull.UP

btn5 = DigitalInOut(btn5_Pin)
Beispiel #15
0
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode
from digitalio import DigitalInOut, Direction, Pull
from analogio import AnalogIn, AnalogOut
from touchio import TouchIn
import adafruit_dotstar as dotstar
import microcontroller
import board
import time

# One pixel connected internally!
dot = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=1)

# Built in red LED
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT

# Analog output on A0
aout = AnalogOut(board.A0)

# Analog input on A1
analog1in = AnalogIn(board.A1)

# Capacitive touch on A2
touch2 = TouchIn(board.A2)

# The keyboard object! Used if we do HID output, see below
time.sleep(1)  # Sleep for a bit to avoid a race condition on some systems

#keyboard = Keyboard(usb_hid.devices)
#keyboard_layout = KeyboardLayoutUS(keyboard)  # We're in the US :)

# One pixel connected internally!
dot = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.08)

# pizeo buzzer
buzzer = PWMOut(board.D5, variable_frequency=True)
buzzer.frequency = 262
OFF = 0
ON = 2**15

# Digital input with pullup on D2, D3, D4, D5, D6
buttons = []
for p in [board.D6, board.D9, board.D10, board.A3, board.A4]:
    button = DigitalInOut(p)
    button.direction = Direction.INPUT
    button.pull = Pull.UP
    buttons.append(button)


# Digital output  on D8, D9, D10, D11, D12
buttonLeds = []
for p in [board.D11, board.D12, board.D13, board.A1, board.A2]:
    buttonLed = DigitalInOut(p)
    buttonLed.direction = Direction.OUTPUT
    buttonLeds.append(buttonLed)

######################### HELPERS ##############################


# Helper to give us a nice color swirl
Beispiel #17
0
import neopixel
import rotaryio
import usb_hid
from adafruit_hid.mouse import Mouse
from adafruit_hid.keyboard import Keyboard, Keycode

# 16 position neopixel ring
ring = neopixel.NeoPixel(board.MISO, 16, brightness=0.2, auto_write=False)

# button of rotary encoder
button = DigitalInOut(board.MOSI)
button.pull = Pull.UP

# Use pin A2 as a fake ground for the rotary encoder
fakegnd = DigitalInOut(board.A2)
fakegnd.direction = Direction.OUTPUT
fakegnd.value = False

encoder = rotaryio.IncrementalEncoder(board.A3, board.A1)

#cc = ConsumerControl(usb_hid.devices)
mouse = Mouse(usb_hid.devices)
keyboard = Keyboard(usb_hid.devices)

print("hello from qtpy-knob-scroller!")


# standard colorwheel
def colorwheel(pos):
    if pos < 0 or pos > 255:
        (r, g, b) = (0, 0, 0)
Beispiel #18
0
sky_blue = [0, 120, 135]
idle_color = [70, 243, 70]
hit_color = [150, 20, 00]

# One pixel connected internally!
dot = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, n=1, brightness=0.2)
dot[0] = sky_blue

led = digitalio.DigitalInOut(board.D13)
led.direction = digitalio.Direction.OUTPUT

# Digital input with pullup on D0

PIR1 = DigitalInOut(board.D0)
PIR1.direction = Direction.INPUT
PIR1.pull = Pull.DOWN

# Digital input with pullup on D2
PIR2 = DigitalInOut(board.D2)
PIR2.direction = Direction.INPUT
PIR2.pull = Pull.DOWN

f_PIR1 = PIR1.value
f_PIR2 = PIR2.value

while True:

	time.sleep(0.5)

	if PIR1.value and not f_PIR1:
Beispiel #19
0
import pulseio
import random
import touchio
from adafruit_motor import servo
from sauce import Sauce
from item_selection import ItemSelection
import busio
from digitalio import DigitalInOut, Direction, Pull

pwm = pulseio.PWMOut(board.A2, duty_cycle=2**15, frequency=50)
pwm1 = pulseio.PWMOut(board.A3, duty_cycle=2**15, frequency=50)
pwm2 = pulseio.PWMOut(board.A4, duty_cycle=2**15, frequency=50)
pwm3 = pulseio.PWMOut(board.D12, duty_cycle=2**15, frequency=50)

pi = DigitalInOut(board.D6)
pi.direction = Direction.INPUT
pi.pull = Pull.UP

sauce_pi = DigitalInOut(board.D7)
sauce_pi.direction = Direction.INPUT
sauce_pi.pull = Pull.UP

sauce_servo = servo.Servo(pwm)
plate_servo = servo.Servo(pwm2)
spat_servo = servo.Servo(pwm3)

sauce_unit = Sauce(sauce_servo, sauce_pi)
uart = busio.UART(board.TX, board.RX, baudrate=9600)
x = 0
plate_unit = ItemSelection(plate_servo, spat_servo, pi)
# button input example
# touch pin D9 to Ground and the LED turns on

import time
import board
from digitalio import DigitalInOut, Direction, Pull
 
yellowLed = DigitalInOut(board.A1) #A1 is the yellow LED that doesn't do PWM
yellowLed.direction = Direction.OUTPUT
 
button = DigitalInOut(board.D9)
button.direction = Direction.INPUT
button.pull = Pull.UP
 
while True:
    if button.value: #if D9 isn't connected to ground
        yellowLed.value = False
    else:
        yellowLed.value = True
 
    #time.sleep(0.01)  # debounce delay
# Creator: Jonathan P-A
# Date: September 30
# This program makes an RGB LED turn on for 1 second and then off for 1 second repetedly
import time
import board
from digitalio import DigitalInOut, Direction

ledi = DigitalInOut(board.D1)
ledii = DigitalInOut(board.D2)
lediii = DigitalInOut(board.D3)
ledi.direction = Direction.OUTPUT
ledii.direction = Direction.OUTPUT
lediii.direction = Direction.OUTPUT

while True:
    ledi.value = True
    ledii.value = True
    lediii.value = True
    time.sleep(1)  #wait 1 second
    ledi.value = False
    ledii.value = False
    lediii.value = False
    time.sleep(1)  #wait 1 second
Beispiel #22
0
import time
from digitalio import DigitalInOut, Direction, Pull

bpm = 120


def play_file(filename):
    f = open(filename, "rb")
    wave = audioio.WaveFile(f)
    a.play(wave)
    time.sleep(bpm / 960)  # sixteenthNote delay


# Enable the speaker
spkrenable = DigitalInOut(board.SPEAKER_ENABLE)
spkrenable.direction = Direction.OUTPUT
spkrenable.value = True

# Make the cap sense pads
touch1 = touchio.TouchIn(board.A1)
touch2 = touchio.TouchIn(board.A2)
touch3 = touchio.TouchIn(board.A3)
touch4 = touchio.TouchIn(board.A4)
touch5 = touchio.TouchIn(board.A5)
touch6 = touchio.TouchIn(board.A6)
touch7 = touchio.TouchIn(board.A7)
touchPad = [touch1, touch2, touch3, touch4, touch5, touch6, touch7]

#this is a list
audiofiles = [
    "bd_tek.wav", "elec_hi_snare.wav", "elec_cymbal.wav", "elec_blip2.wav",
Beispiel #23
0
# NeoTrellis to select colors of NeoPixel strip
# NeoTrellis connected to Feather M4 (need the extra memory vs. M0) SCL, SDA
# NeoPixel 120 strip connected to pin D5
# NeoPixel strip powered over 5V 2A DC wall power supply
# On/off button RGB connects En to GND, LED to D13

import time
import board
from board import SCL, SDA
import busio
import neopixel
from adafruit_neotrellis.neotrellis import NeoTrellis
from digitalio import DigitalInOut, Direction

button_LED = DigitalInOut(board.D13)
button_LED.direction = Direction.OUTPUT
button_LED.value = True

pixel_pin = board.D5
num_pixels = 120

pixels = neopixel.NeoPixel(pixel_pin, num_pixels, auto_write=False)

# create the i2c object for the trellis
i2c_bus = busio.I2C(SCL, SDA)

# create the trellis object
trellis = NeoTrellis(i2c_bus)

# color definitions
OFF = (0, 0, 0)
Beispiel #24
0
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise
# Debug Level
# Change the Debug Flag if you have issues with AT commands
debugflag = False

if board.board_id == "challenger_rp2040_wifi":
    RX = board.ESP_RX
    TX = board.ESP_TX
    resetpin = DigitalInOut(board.WIFI_RESET)
    rtspin = False
    uart = busio.UART(TX, RX, baudrate=11520, receiver_buffer_size=2048)
    esp_boot = DigitalInOut(board.WIFI_MODE)
    esp_boot.direction = Direction.OUTPUT
    esp_boot.value = True
else:
    RX = board.ESP_TX
    TX = board.ESP_RX
    resetpin = DigitalInOut(board.ESP_WIFI_EN)
    rtspin = DigitalInOut(board.ESP_CTS)
    uart = busio.UART(TX, RX, timeout=0.1)
    esp_boot = DigitalInOut(board.ESP_BOOT_MODE)
    esp_boot.direction = Direction.OUTPUT
    esp_boot.value = True

print("ESP AT commands")
# For Boards that do not have an rtspin like challenger_rp2040_wifi set rtspin to False.
esp = adafruit_espatcontrol.ESP_ATcontrol(uart,
                                          115200,
Beispiel #25
0
import board
import neopixel
import time
from digitalio import DigitalInOut, Direction, Pull
import random

btn = DigitalInOut(board.GP20)
btn.direction = Direction.INPUT
btn.pull = Pull.UP
pixelCount = 16

pixels = neopixel.NeoPixel(board.GP26,
                           pixelCount,
                           brightness=.1,
                           auto_write=False)
print("init the neopixels")
#pixels = neopixel.NeoPixel(board.GP1, 16, brightness = 0.5)
#pixels[0] = (10, 0, 0)
pixels.fill((255, 0, 255))

MAX_PINK_RED = 247
MAX_PINK_GREEN = 74
MAX_PINK_BLUE = 230


def rainbow_cycle(wait, step):
    j = step
    for i in range(pixelCount):
        rc_index = (i * 256 // 10) + j * 5
        pixels[i] = wheel(rc_index & 255)
    pixels.show()
# Playground 808
# Drum machine
import time

import audioio
import board
import touchio
from digitalio import DigitalInOut, Direction

bpm = 120  # beats per minute, change this to suit your tempo

# enable the speaker
spkrenable = DigitalInOut(board.SPEAKER_ENABLE)
spkrenable.direction = Direction.OUTPUT
#spkrenable.value = True ## Send sound out internal speaker and A0 Pin
spkrenable.value = False  ## Only send sound out the A0 Pin

# make the input cap sense pads
capPins = (board.A1, board.A2, board.A3, board.A4, board.A5, board.A6,
           board.A7)

touchPad = []
for i in range(7):
    touchPad.append(touchio.TouchIn(capPins[i]))

# The seven files assigned to the touchpads
audiofiles = [
    "bd_tek.wav", "elec_hi_snare.wav", "elec_cymbal.wav", "elec_blip2.wav",
    "bd_zome.wav", "bass_hit_c.wav", "drum_cowbell.wav"
]
    group.append(nextHourTempLabel)

    nextHourLabel = label.Label(font_small, text="+8", color=0x000000)
    nextHourLabel.text = "+{}".format(hour)
    nextHourLabel.anchor_point = (0.5, 0.0)
    nextHourLabel.anchored_position = (10, -7)
    group.append(nextHourLabel)

    return group

# Wrap everything in a try block so we can restart if anything fails
try:

    # turn light sensor on
    power = DigitalInOut(board.NEOPIXEL_POWER)
    power.direction = Direction.OUTPUT
    power.value = False

    light_sensor = AnalogIn(board.LIGHT)

    #give it a moment to read (just a guess)
    time.sleep(0.05)

    light_value = light_sensor.value
    power.value = True # turn the sensor offset

    print("Light is:", light_value)

    # No need to update the screen if it is dark and you can't read it
    if light_value > 600:
#
# SPDX-License-Identifier: MIT

#  Animatronic Hand
#  Binary Counting on four fingers up to 15
import time
from digitalio import DigitalInOut, Direction, Pull
import audioio
import audiocore
import board
from adafruit_crickit import crickit

#################### CPX switch
# use the CPX onboard switch to turn on/off (helps calibrate)
switch = DigitalInOut(board.SLIDE_SWITCH)
switch.direction = Direction.INPUT
switch.pull = Pull.UP

#################### Audio setup
print("Let's count in binary.")
wavfiles = ("one.wav", "two.wav", "three.wav", "four.wav", "five.wav",
            "six.wav", "seven.wav", "eight.wav", "nine.wav", "ten.wav",
            "eleven.wav", "twelve.wav", "thirteen.wav", "fourteen.wav",
            "fifteen.wav")
introfile = "intro.wav"

cpx_audio = audioio.AudioOut(board.A0)


def play_file(wavfile):
    with open(wavfile, "rb") as f:
Beispiel #29
0
    draw.rectangle((0, 0, oled.width, oled.height * 2), outline=0, fill=0)
    draw.text((0,0), firstLine, font=font, fill=255)
    draw.text((0,18), secondLine, font=font, fill=255)
    draw.text((0,36), thirdLine, font=font, fill=255)
    oled.image(image)
    oled.show()
        

# i2c interface and display
i2c = board.I2C()
RESET_PIN = digitalio.DigitalInOut(board.D4)
oled = adafruit_ssd1306.SSD1306_I2C(128, 64, i2c, addr=0x3c, reset=RESET_PIN)

# button and joystick input
leftButton = DigitalInOut(board.D5)
leftButton.direction = Direction.INPUT
leftButton.pull = Pull.UP
 
rightButton = DigitalInOut(board.D6)
rightButton.direction = Direction.INPUT
rightButton.pull = Pull.UP
 
leftJoy = DigitalInOut(board.D27)
leftJoy.direction = Direction.INPUT
leftJoy.pull = Pull.UP
 
rightJoy = DigitalInOut(board.D23)
rightJoy.direction = Direction.INPUT
rightJoy.pull = Pull.UP
 
upJoy = DigitalInOut(board.D17)
Beispiel #30
0
# CircuitPlaygroundExpress_DigitalIO

import time

import board
from digitalio import DigitalInOut, Direction, Pull

led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT

button = DigitalInOut(board.BUTTON_A)
button.direction = Direction.INPUT
button.pull = Pull.DOWN

while True:
    if button.value:  # button is pushed
        led.value = True
    else:
        led.value = False

    time.sleep(0.01)

import time
import board
from digitalio import DigitalInOut, Direction, Pull
from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface
from lcd.lcd import CursorMode

lcd = LCD(I2CPCF8574Interface(0x27), num_rows=2, num_cols=16)
button = DigitalInOut(board.D2)     #make button pin
button.direction = Direction.INPUT  
button.pull = Pull.UP               #give power to button
switch = DigitalInOut(board.D5)     #make switch pin
switch.direction = Direction.INPUT
switch.pull = Pull.UP               #give power to switch
lcd.set_cursor_mode(CursorMode.LINE)

press = False #press starts at false until proven otherwise
x = 0       #starts at 0

while True:
    print(button.value)
    lcd.backlight = True       #backlight is on
    if not button.value:
        if (press == False):
            press = True   #if press does not equal false then press equals true
            if not switch.value:
                x = x -1        #if it does not equal switch value then it goes down by one
            if switch.value:
                x = x +1        #if it does equal switch value then it goes up by one
        print((0,))
    if button.value:
Beispiel #32
0
import board
import time
import neopixel
from digitalio import DigitalInOut, Direction, Pull
from analogio import AnalogIn
import audioio
import touchio
import simpleio


# One pixel connected internally!
dot = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.2)

# Built in red LED
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT

# Digital input with pullup on D2, D3, and D4
buttons = []
for p in [board.D2, board.D3, board.D4]:
    button = DigitalInOut(p)
    button.direction = Direction.INPUT
    button.pull = Pull.UP
    buttons.append(button)


######################### HELPERS ##############################
##

# Helper to give us a nice color swirl
def wheel(pos):
Beispiel #33
0
Author: Brent Rubell for Adafruit Industries
"""
# Import Python System Libraries
import time
# Import Blinka Libraries
import busio
from digitalio import DigitalInOut, Direction, Pull
import board
# Import the SSD1306 module.
import adafruit_ssd1306
# Import RFM9x
import adafruit_rfm9x
 
# Button A
btnA = DigitalInOut(board.D5)
btnA.direction = Direction.INPUT
btnA.pull = Pull.UP
 
# Button B
btnB = DigitalInOut(board.D6)
btnB.direction = Direction.INPUT
btnB.pull = Pull.UP
 
# Button C
btnC = DigitalInOut(board.D12)
btnC.direction = Direction.INPUT
btnC.pull = Pull.UP
 
# Create the I2C interface.
i2c = busio.I2C(board.SCL, board.SDA)
 
Beispiel #34
0
import board
import array
import time
from digitalio import DigitalInOut, Direction, Pull
import pulseio

############## Switch to select 'stealth-mode'
switch = DigitalInOut(board.SLIDE_SWITCH)
switch.direction = Direction.INPUT
switch.pull = Pull.UP
# Button to see output debug
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT

############## Speaker as haptic feedback
spkr_en = DigitalInOut(board.SPEAKER_ENABLE)
spkr_en.direction = Direction.OUTPUT
spkr_en.value = False
spkr = DigitalInOut(board.SPEAKER)
spkr.direction = Direction.OUTPUT

############## Allow any button to trigger activity!
button_a = DigitalInOut(board.BUTTON_A)
button_a.direction = Direction.INPUT
button_a.pull = Pull.DOWN
button_b = DigitalInOut(board.BUTTON_B)
button_b.direction = Direction.INPUT
button_b.pull = Pull.DOWN


pwm = pulseio.PWMOut(board.REMOTEOUT, frequency=38000, duty_cycle=2 ** 15, variable_frequency=True)
Beispiel #35
0
import time
import board
import busio, supervisor, os

from digitalio import DigitalInOut, Direction  # pylint: disable=unused-import
import adafruit_miniesptool

print("ESP32 mini prog")

resetpin = DigitalInOut(board.RTS)
gpio0pin = DigitalInOut(board.DTR)
resetpin.direction = Direction.OUTPUT
gpio0pin.direction = Direction.OUTPUT

resetpin.value = 1
gpio0pin.value = 1

import adafruit_sdcard, storage

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
cs = DigitalInOut(board.xSDCS)
sdcard = adafruit_sdcard.SDCard(spi, cs)
vfs = storage.VfsFat(sdcard)
storage.mount(vfs, "/sd")


def print_directory(path, tabs=0):
    for file in os.listdir(path):
        stats = os.stat(path + "/" + file)
        filesize = stats[6]
        isdir = stats[0] & 0x4000
Beispiel #36
0
# keyboard imports
import usb_hid
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS
from adafruit_hid.keycode import Keycode as KC
from adafruit_hid.consumer_control_code import ConsumerControlCode
from adafruit_hid.consumer_control import ConsumerControl

# rotary encoder
import rotaryio
encoder = rotaryio.IncrementalEncoder(board.P1_11, board.P0_29)
encoder_last_position = encoder.position

encoder_switch_pin = DigitalInOut(board.P0_31)
encoder_switch_pin.direction = Direction.INPUT
encoder_switch_pin.pull = Pull.UP

encoder_switch_last_position = True


def encoder_update():
    global encoder_last_position
    global encoder_switch_last_position
    if encoder_last_position > encoder.position:
        encoder_last_position = encoder.position
        keyboard_consumer_control.send(ConsumerControlCode.VOLUME_INCREMENT)
    elif encoder_last_position < encoder.position:
        encoder_last_position = encoder.position
        keyboard_consumer_control.send(ConsumerControlCode.VOLUME_DECREMENT)
Beispiel #37
0
from time import sleep

import board
import neopixel
from digitalio import DigitalInOut, Direction, Pull 
from supervisor import runtime

from cpgame import after, cancel, every, on, start
from colors import RED, ORANGE, GREEN, YELLOW, BLUE, VIOLET, WHITE, OFF

pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=0.02, auto_write=True)
pixels.fill(OFF)
pixels.show()

WAIT = DigitalInOut(board.D7)
WAIT.direction = Direction.INPUT
WAIT.pull = Pull.UP

LED = DigitalInOut(board.D13)
LED.direction = Direction.OUTPUT

STATUS = 9

class state:
    active = 0
    handshake = 0
    data = ""


def send(cmd):
    if cmd.endswith("\n"):