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
from digitalio import DigitalInOut, Direction, Pull
import time
import board

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

counter = 0

photo = False
state = False

max = 4
start = time.time()
while True:
    photo = interrupter.value
    if photo and not state:
        counter += 1
    state = photo

    remaining = max - time.time()

    if remaining <= 0:
        print("Interrupts:", str(counter))
        max = time.time() + 4
        counter = 0
# set up dotstar indicator output (GBR orientation)
dot = dotstar.DotStar(board.DOTSTAR_CI, board.DOTSTAR_DI, 1, brightness=0.5)

# set up busy indicator output (red LED)
busy = DigitalInOut(board.LED_STATUS)
busy.direction = Direction.OUTPUT

# set up motor controller outputs
ain01 = pulseio.PWMOut(board.MOTOR_OUT_1, frequency=25, duty_cycle=0)
ain02 = pulseio.PWMOut(board.MOTOR_OUT_2, frequency=25, duty_cycle=0)

# set up EOS sensor switch input
sensor_eos = DigitalInOut(board.SENSOR_IN)
sensor_eos.direction = Direction.INPUT
sensor_eos.pull = Pull.UP

# Analog input on VOLTAGE_MONITOR
v_plus = AnalogIn(board.VOLTAGE_MONITOR)

# set up potentiometer control input
#ctl = AnalogIn(board.D1)

# set up piezo output
piezo = pulseio.PWMOut(board.PIEZO,
                       duty_cycle=0,
                       frequency=440,
                       variable_frequency=True)


def setup(motor_specs):
Beispiel #4
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)
button_U.direction = Direction.INPUT
index = 8  # midway color selection
blend = True  # color blending between palette indices

# initialize list with all pixels off
palette = [0] * num_leds

# Declare a NeoPixel object on led_pin with num_leds as pixels
# No auto-write.
# Set brightness to max.
# We will be using FancyLED's brightness control.
strip = neopixel.NeoPixel(led_pin, num_leds, brightness=1, auto_write=False)

# button setup
button = DigitalInOut(board.D2)
button.direction = Direction.INPUT
button.pull = Pull.UP
prevkeystate = False
ledmode = 0  # button press counter, switch color palettes

# FancyLED allows for assigning a color palette using these formats:
# * The first (5) palettes here are mixing between 2-elements
# * The last (3) palettes use a format identical to the FastLED Arduino Library
# see FastLED - colorpalettes.cpp
forest = [fancy.CRGB(0, 255, 0),  # green
          fancy.CRGB(255, 255, 0)]  # yellow

ocean = [fancy.CRGB(0, 0, 255),  # blue
         fancy.CRGB(0, 255, 0)]  # green

purple = [fancy.CRGB(160, 32, 240),  # purple
          fancy.CRGB(238, 130, 238)]  # violet
Beispiel #6
0
#FILENAME = "minerva.bmp"

TOUCH = touchio.TouchIn(board.A5)  #  capacitive touch pad
SPEED = 10000
SPEED_ADJUST = 2500  # This value changes the increment for button speed adjustments
BRIGHTNESS = 1.0  # Set brightness here, NOT in NeoPixel constructor
GAMMA = 2.7  # Adjusts perceived brighthess linearity
NUM_PIXELS = 30  # NeoPixel strip length (in pixels)
NEOPIXEL_PIN = board.A1  # Pin where NeoPixels are connected
DELAY_TIME = 0.01  # Timer delay before it starts
LOOP = False  # Set to True for looping

# button setup
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

# switch setup
switch = DigitalInOut(board.SLIDE_SWITCH)
switch.direction = Direction.INPUT
switch.pull = Pull.UP

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

if switch.value:
"""
This example script shows how to read button state with
debouncing that does not rely on time.sleep().
"""

import board
from digitalio import DigitalInOut, Direction, Pull

btn = DigitalInOut(board.SWITCH)
btn.direction = Direction.INPUT
btn.pull = Pull.UP

prev_state = btn.value

while True:
    cur_state = btn.value
    if cur_state != prev_state:
        if not cur_state:
            print("BTN is down")
        else:
            print("BTN is up")

    prev_state = cur_state
Beispiel #8
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:
		dot[0] = hit_color
Beispiel #9
0
    (15): (KEY, [Keycode.O]),
    (16): (KEY, [Keycode.LEFT_ARROW]),
    (17): (KEY, [Keycode.DOWN_ARROW]),
    (18): (KEY, [Keycode.RIGHT_ARROW]),
    (19): (KEY, [Keycode.ALT]),
    (20): (KEY, [Keycode.U]),
}
switches = [
    0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
    21
]

for i in range(21):
    switches[i] = DigitalInOut(pins[i])
    switches[i].direction = Direction.INPUT
    switches[i].pull = Pull.UP

switch_state = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

while True:
    for button in range(21):
        if switch_state[button] == 0:
            if not switches[button].value:
                try:
                    if keymap[button][0] == KEY:
                        kbd.press(*keymap[button][1])
                    else:
                        cc.send(keymap[button][1])
                except ValueError:  # deals w six key limit
                    pass
                switch_state[button] = 1
# 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

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

dot = neopixel.NeoPixel(board.NEOPIXEL, 1)
lcd = LCD(I2CPCF8574Interface(0x27), num_rows=2, num_cols=16)

r = 255
g = 0
b = 0

toggle = True
time_toggle = True

current_time = 0

interrupts = 0

while True:
    dot.fill((r, g, b))
Beispiel #11
0
# import modules
import board
import neopixel
from digitalio import DigitalInOut, Direction, Pull
import time

# declare objects and variables
switch = DigitalInOut(board.SLIDE_SWITCH)
switch.direction = Direction.INPUT
switch.pull = Pull.UP

buttonA = DigitalInOut(board.BUTTON_A)
buttonA.direction = Direction.INPUT
buttonA.pull = Pull.DOWN
buttonAPre = False

buttonB = DigitalInOut(board.BUTTON_B)
buttonB.direction = Direction.INPUT
buttonB.pull = Pull.DOWN
buttonBPre = False

pixels = neopixel.NeoPixel(board.NEOPIXEL,
                           10,
                           brightness=.05,
                           auto_write=False)

# color variables
OFF = (0, 0, 0)
WHITE = (255, 255, 255)
ORANGE = (255, 35, 0)
BLUE = (0, 0, 255)
Beispiel #12
0
from adafruit_motor import servo
from busio import I2C
import neopixel
import board

# Create seesaw object
i2c = I2C(board.SCL, board.SDA)
seesaw = Seesaw(i2c)

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

# Two onboard CPX buttons for FOG
buttona = DigitalInOut(board.BUTTON_A)
buttona.direction = Direction.INPUT
buttona.pull = Pull.DOWN

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

# Use the signal port for potentiometer w/switch
MORECOW = 2  # A switch on Signal #1
SWITCH = 3  # A potentiometer on Signal #2
# Add a pullup on the switch
seesaw.pin_mode(SWITCH, seesaw.INPUT_PULLUP)

# Servo angles
BELL_START = 60
BELL_END = 75
MOUTH_START = 95
Beispiel #13
0
Please support Adafruit and open source hardware by purchasing
products from Adafruit!

Written by Dave Astels for Adafruit Industries
Copyright (c) 2018 Adafruit Industries
Licensed under the MIT license.

All text above must be included in any redistribution.
"""
import board
from digitalio import DigitalInOut, Direction, Pull
from adafruit_circuitplayground import cp

button_a = DigitalInOut(board.A1)
button_a.direction = Direction.INPUT
button_a.pull = Pull.UP

button_b = DigitalInOut(board.A2)
button_b.direction = Direction.INPUT
button_b.pull = Pull.UP

cp.pixels.brightness = 0.3
cp.pixels.fill((0, 0, 0))  # Turn off the NeoPixels if they're on!


def touch_a():
    return not button_a.value


def touch_b():
    return not button_b.value
Beispiel #14
0
# See https://learn.adafruit.com/circuitpython-essentials/circuitpython-storage
# for a discussion
#
import board
from digitalio import DigitalInOut, Direction, Pull
import storage

# Use DPAD switches to control filesystem mode
#
left_pin = DigitalInOut(board.D3)
left_pin.direction = Direction.INPUT
left_pin.pull = Pull.UP

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

up_pin = DigitalInOut(board.D1)
up_pin.direction = Direction.INPUT
up_pin.pull = Pull.UP

down_pin = DigitalInOut(board.D0)
down_pin.direction = Direction.INPUT
down_pin.pull = Pull.UP

# If any DPAD switch is not pressed, then CircuitPython can write to the drive.
# To allow the host to write, press all 4 DPAD buttons during boot.
#
print("DPAD left  = ", left_pin.value)
print("DPAD right = ", right_pin.value)
print("DPAD up    = ", up_pin.value)
    #     "num_pixels": 8,
    #     "order": neopixel.GRB,
    #     "brightness_lvl": 0.2,
    #     "led_object": None,
    # },
    # "left_middle": {},
    # "right_rib": {},
    # "right_chest": {},
    # "right_abs": {},
    # "right_middle": {},
}

# BUTTON REGISTER
button = DigitalInOut(board.BUTTON_A)
button.direction = Direction.INPUT
button.pull = Pull.DOWN
# BUTTON STATES
prevkeystate = False
ledmode = 0  # button press counter, switch color palettes

memorySnapshot()

# TODO: Add the other devices
# SETUP
create_neopixel_objects(device="left_rib")
# create_neopixel_objects(device="left_chest")
# create_neopixel_objects(device="left_abs")
# create_neopixel_objects(device="left_middle")
# create_neopixel_objects(device="right_rib")
# create_neopixel_objects(device="right_chest")
# create_neopixel_objects(device="right_abs")
Beispiel #16
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)
import adafruit_dotstar as dotstar
import neopixel
import board
import time
from digitalio import DigitalInOut, Direction, Pull

dot = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.2)

led_pin = board.D1  # Which pin your pixels are connected to
num_leds = 10  # How many LEDs you have
strip = neopixel.NeoPixel(led_pin, num_leds, brightness=1, auto_write=False)
b1 = DigitalInOut(board.D2)
b1.direction = Direction.INPUT
b1.pull = Pull.UP
b2 = DigitalInOut(board.D0)
b2.direction = Direction.INPUT
b2.pull = Pull.UP

SOFTCYAN = (0, 85, 85)
SOFTYELLOW = (85, 76, 0)
WHEEL = (0, 0, 0)
WHITE = (255, 255, 255)
CYAN = (0, 255, 255)
YELLOW = (255, 230, 0)
RED = (255, 10, 30)
BLUE = (30, 10, 255)
GREEN = (30, 255, 10)

COLORS = [SOFTCYAN, SOFTYELLOW, WHEEL, WHITE, CYAN, YELLOW, RED, BLUE, GREEN]

Beispiel #18
0
import random

dotstar = DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=0.3)
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT
rightEye = DigitalInOut(board.D0)
leftEye = DigitalInOut(board.D3)
sensor = DigitalInOut(board.D4)
piezo = pulseio.PWMOut(board.D2,
                       duty_cycle=0,
                       frequency=250,
                       variable_frequency=True)
rightEye.direction = Direction.OUTPUT
leftEye.direction = Direction.OUTPUT
sensor.direction = Direction.INPUT
sensor.pull = Pull.UP

loopCount = 0

rightEye.value = True
leftEye.value = True

dotstar[0] = (0, 0, 255)


def moved():
    dotstar[0] = (255, 255, 0)
    squeak(3)
    time.sleep(2)

Beispiel #19
0
# For the Metro
cs = digitalio.DigitalInOut(board.D10)
dc = digitalio.DigitalInOut(board.D9)


display = ili9341.ILI9341(spi, cs=cs, dc=dc, width=320, height=240)
display.write(0x36, b'\x3E')

bf = bitmapfont.BitmapFont(320, 240, display.pixel)  # (240, 320, display.pixel)
bf.init()
 
led = simpleio.DigitalOut(board.D13)
GoButton = DigitalInOut(board.D4)  # pin 4 gets 3.3v to start the party.
GoButton.direction = Direction.INPUT
GoButton.pull = Pull.UP
  
def Rounder(IntInput, MaxNum):
    if (IntInput > MaxNum):
        # print("number over " + (str(MaxNum)) + "! Lowered " + (str(IntInput))) 
        IntInput /= 2
        IntInput = int(round(IntInput))
        # print(" to:" + (str(IntInput)))
        # print("")
    return(IntInput)
    
def Limiter(IntInput, MaxNum):
    while (IntInput > MaxNum):
        # print("number over " + (str(MaxNum)) + "! Lowered " + (str(IntInput))) 
        IntInput /= 2
        IntInput = int(round(IntInput))
import time
import board  #these libraries are needed
from digitalio import DigitalInOut, Direction, Pull
from lcd.lcd import LCD
from lcd.i2c_pcf8574_interface import I2CPCF8574Interface

lcd = LCD(I2CPCF8574Interface(0x27), num_rows=2, num_cols=16)
PI = DigitalInOut(board.D5)
PI.direction = Direction.INPUT  #making photointerrupter pin and declaring as DigitalInOut object
PI.pull = Pull.UP

x = 0  #Set at zero until proven otherwise

interrupt = False
while True:
    #print(PI.value)
    lcd.backlight = True
    if PI.value:
        if interrupt == False:
            interrupt = True  #if interrupt isn't false then it is true
            x = x + 1  #count up by one if PI value
    if not PI.value:
        interrupt = False  #if not PI value then it is back to starting x=0
        x = x

    #print(("Interrupted"))
    if time.monotonic() % 4 == 0:  #print value every 4 times PI is interrupted
        lcd.set_cursor_pos(0, 0)  #cursor at start of first row
        lcd.print("Interrupted: ")
        lcd.set_cursor_pos(0, 12)  #cursor at end of first row
        lcd.print(str(x))
from adafruit_seesaw.pwmout import PWMOut

from adafruit_motor import servo
from busio import I2C
import board

# Create seesaw object for Circuit Playground Express to talk to Crickit
i2c = I2C(board.SCL, board.SDA)
seesaw = Seesaw(i2c)

led = DigitalInOut(board.D13)  # Set up Red LED
led.direction = Direction.OUTPUT

button_A = DigitalInOut(board.BUTTON_A)  # Set up switch A
button_A.direction = Direction.INPUT
button_A.pull = Pull.DOWN

# Create servos list
servos = []
for ss_pin in (17, 16):  # Only use 2 servos, append , 15, 14 if using 4
    pwm = PWMOut(seesaw, ss_pin)
    pwm.frequency = 50
    _servo = servo.Servo(pwm, min_pulse=600, max_pulse=2500)
    _servo.angle = 90  # starting angle, middle
    servos.append(_servo)


def servo_front(direction):
    if direction > 0:
        index = 50
        while index <= 90:
import neopixel
from digitalio import DigitalInOut, Direction, Pull
import time

brightness = 0.0
target = 0.5

pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=brightness)
pixels.fill((255, 255, 255))

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

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

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

press = DigitalInOut(board.A1)
press.direction = Direction.INPUT
press.pull = Pull.UP

rotary_left = DigitalInOut(board.A2)
rotary_left.direction = Direction.INPUT
rotary_left.pull = Pull.DOWN

rotary_right = DigitalInOut(board.A3)
rotary_right.direction = Direction.INPUT
Beispiel #23
0
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 variables for the r, g, b values for the built-in led
# on the board

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

lcd = LCD(I2CPCF8574Interface(0x27), num_rows=2, num_cols=16)

mods = [1, 2, 5, 10, -1, -2, -5, -10]

num = 0
m = 0
Beispiel #24
0
if len(addrs) == 4:
    if '1e' in addrs:
        if '39' in addrs:
            if '6b' in addrs:
                if '76' in addrs:
                    iicdevs = "V"
                    print("All devices present!")

iicdevstr = ""
for h in addrs:
    iicdevstr += h

print('Checking Charge Status Pin')
charge_status = DigitalInOut(m.pin.P0_16)
charge_status.direction = Direction.INPUT
charge_status.pull = Pull.UP
print("Charge Pin:\t%s" % (str(charge_status.value)))

print("Checking Battery Voltage")
analog_in = AnalogIn(m.pin.P0_31)
print("Voltage:\t%s" % (str(analog_in.value)))

qrstring = bytes(
    ",IIC:%s,IICDEV:%s,ADC:%s" %
    (iicdevs, iicdevstr, str(analog_in.value).strip()), 'utf-8')
print(qrstring)
qr = adafruit_miniqr.QRCode()
qr.add_data(qrstring)
qr.make()

palette = displayio.Palette(2)
Beispiel #25
0
"""


import json


from digitalio import DigitalInOut, Direction, Pull
import analogio


light = analogio.AnalogIn(board.LIGHT)

snooze_button = DigitalInOut(board.D3)
snooze_button.direction = Direction.INPUT
snooze_button.pull = Pull.UP

####################
# variables

# mugsy support
mugsy_background = 'mugsy_background.bmp'

# weather support

icon_file = None
icon_sprite = None
celcius = secrets['celcius']

# display/data refresh timers
# Demo the Piper Command Center Joystick library
#
import board
from digitalio import DigitalInOut, Direction, Pull
from adafruit_hid.mouse import Mouse
import usb_hid
from adafruit_debouncer import Debouncer
from piper_command_center import PiperJoystickAxis

# Setup DPAD
#
left_pin = DigitalInOut(board.D3)
left_pin.direction = Direction.INPUT
left_pin.pull = Pull.UP
left = Debouncer(left_pin)

right_pin = DigitalInOut(board.D4)
right_pin.direction = Direction.INPUT
right_pin.pull = Pull.UP
right = Debouncer(right_pin)

# Provide a ground for the joystick - this is to facilitate
# easier wiring
joystick_gnd = DigitalInOut(board.A5)
joystick_gnd.direction = Direction.OUTPUT
joystick_gnd.value = 0

# Setup joystick pins, and choose an outputScale which results in an
# easy to control mouse pointer
#
x_axis = PiperJoystickAxis(board.A4, outputScale=20)
# 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
def wheel(pos):
Beispiel #28
0
BUTTON_PIN = board.D17
JOYDOWN_PIN = board.D27
JOYLEFT_PIN = board.D22
JOYUP_PIN = board.D23
JOYRIGHT_PIN = board.D24
JOYSELECT_PIN = board.D16

buttons = [
    BUTTON_PIN, JOYUP_PIN, JOYDOWN_PIN, JOYLEFT_PIN, JOYRIGHT_PIN,
    JOYSELECT_PIN
]

for i, pin in enumerate(buttons):
    buttons[i] = DigitalInOut(pin)
    buttons[i].direction = Direction.INPUT
    buttons[i].pull = Pull.UP
button, joyup, joydown, joyleft, joyright, joyselect = buttons


class Input(Enum):
    BUTTON = auto()
    UP = auto()
    DOWN = auto()
    LEFT = auto()
    RIGHT = auto()
    SELECT = auto()


def get_inputs():
    inputs = []
    if not button.value:
Beispiel #29
0
import board
import time
import usb_hid

from digitalio import DigitalInOut, Direction, Pull
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode

switch = DigitalInOut(board.GP4)
switch.direction = Direction.INPUT
switch.pull = Pull.UP

bt1 = DigitalInOut(board.GP18)
bt1.direction = Direction.INPUT
bt1.pull = Pull.UP

bt2 = DigitalInOut(board.GP20)
bt2.direction = Direction.INPUT
bt2.pull = Pull.UP

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

keyboard = Keyboard(usb_hid.devices)

while True:
    if not bt1.value:
        if switch.value:
            #MacOs
            print("Button 1, Switch position 1")
            led.value = not led.value
Beispiel #30
0
from digitalio import DigitalInOut, Direction, Pull
from adafruit_seesaw.seesaw import Seesaw
from adafruit_seesaw.pwmout import PWMOut
from adafruit_motor import servo, motor
from busio import I2C
import board

i2c = I2C(board.SCL, board.SDA)
ss = Seesaw(i2c)

print("Crickit demo!")

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

#################### 4 Servos
servos = []
for ss_pin in (17, 16, 15, 14):
    pwm = PWMOut(ss, ss_pin)
    pwm.frequency = 50
    _servo = servo.Servo(pwm)
    _servo.angle = 90  # starting angle, middle
    servos.append(_servo)

#################### 2 DC motors
motors = []
for ss_pin in ((22, 23), (18, 19)):
    pwm0 = PWMOut(ss, ss_pin[0])
    pwm1 = PWMOut(ss, ss_pin[1])
Beispiel #31
0
def cbackRelease():
    k.release_all()
    dot[0] = (0, 0, 0)
    led.value = 0


dot = dotstar.DotStar(board.APA102_SCK, board.APA102_MOSI, 1, brightness=lB)
dot[0] = (0, 0, 0)

k = Keyboard()
kL = KeyboardLayoutUS(k)

bR = DigitalInOut(board.D2)
bR.direction = Direction.INPUT
bR.pull = Pull.DOWN

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

tA = touchio.TouchIn(board.D3)
tB = touchio.TouchIn(board.D4)
tC = touchio.TouchIn(board.D1)

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


def calibrate():
    sTime = time.monotonic()
Beispiel #32
0
# Import Blinka Libraries
import busio
from digitalio import DigitalInOut, Direction, Pull
import board
# Import the SSD1306 module.
import adafruit_ssd1306
# Import the RFM69 radio module.
import adafruit_rfm69

#############################################################################
# Initialize RFM69 Board
#############################################################################
# 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)

# 128x32 OLED Display
Beispiel #33
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:
        dot[0] = hit_color
# SPDX-License-Identifier: MIT

import board
from digitalio import DigitalInOut, Direction, Pull
from adafruit_funhouse import FunHouse
from adafruit_debouncer import Debouncer

RED = 0x200000
GREEN = 0x002000

funhouse = FunHouse(default_bg=None)
funhouse.peripherals.dotstars.fill(RED)

switch_pin = DigitalInOut(board.A1)
switch_pin.direction = Direction.INPUT
switch_pin.pull = Pull.UP
switch = Debouncer(switch_pin)


def send_io_data(door_value):
    funhouse.peripherals.led = True
    print("Sending data to adafruit IO!")
    funhouse.network.push_to_io("door", door_value)
    funhouse.peripherals.led = False


send_io_data(0)

while True:

    switch.update()
Beispiel #35
0
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"):
        line = cmd