Beispiel #1
0
            at_top = True
            set_drive(True, False, False)


home_pickles()
print_status("Homed")

# Main Program
state = 0
cycle_start = time.monotonic()

while True:
    if state is 0:
        if drop.value is False or time.monotonic(
        ) - cycle_start > CYCLE_TIME * 60:
            sound.value, light.value = True, True
            time.sleep(5)
            print_status("Dropping")
            state = 1

    if state is 1:  # drop down, slow at the end
        set_drive(False, False, False)

        if lower_slow.value is False:
            slow_start = time.monotonic()
            print_status("Stopping")

            while time.monotonic() - slow_start < BOTTOM_SLOW:  # feather brake
                set_drive(True, False, False)
                time.sleep(BRAKE_TIME * BRAKE_RATE)
                set_drive(False, False, False)
Beispiel #2
0
def setAngle(angle, msec):
    step = [0, 0, 0, 0, 0, 0, 0, 0]
    msec = msec / motionSpeed # now 15//default 10; //speedy 20   Speed Adj
    for val in range(8):
        target = servoSetInit[val] - angle[val]
        target = min(max(target, 0), 1800)
        if target != servoAngle[val]: # Target != Present
            step[val] = (target - servoAngle[val]) / msec
    #print(step)
    for _ in range(msec):
        for val in range(8):
            servoAngle[val] += step[val]
            #print("setting servo %d to %d" % (val, int(servoAngle[val] / 10)))
            servoWrite(val, servoAngle[val] / 10)
        #time.sleep(msec / 1000)
    print(servoAngle)

servoInitialSet()

led.value = False
setAngle([0, 0, -200, 0, 0, 0, 0, 0], 500)
setAngle([0, 0, -1800, 0, 0, 0, 1800, 0], 500)
setAngle([900, 0, -1800, 0, -900, 0, 1800, 0], 500)
setAngle([900, 0, -200, 0, -900, 0, 0, 0], 500)
setAngle([900, 0, -1800, 0, -900, 0, 1800, 0], 500)
setAngle([900, 0, -200, 0, -900, 0, 0, 0], 500)
setAngle([0, 0, -200, 0, 0, 0, 0, 0], 500)
led.value = True

servoFree()
Beispiel #3
0
TH1 = 5000
TH2 = 17000
TH3 = 29000
TH4 = 41000
TH5 = 53000



 while True:
     analogValue = analogIn.value

     print((analogIn.value, TH1, TH2, TH3, TH4, TH5))

     if analogValue > TH5:
        led1.value = True
        led2.value = True
        led3.value = True
        led4.value = True
        led5.value = True
     elif analogValue > TH4:
        led1.value = True
        led2.value = True
        led3.value = True
        led4.value = True
        led5.value = False
     elif analogValue > TH3:
        led1.value = True
        led2.value = True
        led3.value = True
        led4.value = False
import time

import board
from digitalio import DigitalInOut, Direction, Pull

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

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

while True:
    if button.value:
        led.value = True  # check if the pushbutton is pressed.
    else:
        led.value = False  # turn LED off

    time.sleep(0.01)  # debounce delay
Beispiel #5
0
fwd_cmd = str.encode("f")
rev_cmd = str.encode("r")
fast_cmd = str.encode("h")
slow_cmd = str.encode("l")
fstep_cmd = str.encode("u")
rstep_cmd = str.encode("d")
x_cmd = str.encode("x")

flag = True
while True:
    uart.start_advertising()

    # Wait for a connection
    while not uart.connected:
        Gled.value = True
        Rled.value = False

        FWD_PIN.value = False
        REV_PIN.value = False
        SLOW_PIN.value = False
        FAST_PIN.value = False
        FSTEP_PIN.value = False
        RSTEP_PIN.value = False
        pass

    while uart.connected:
        one_byte = uart.read(1)
        print(one_byte)

        if one_byte:
# stringcar_m0_ex_init_test_2020-09-03
# Cedar Grove StringCar M0 Express v06 initial test
import board
import time
import pulseio
from digitalio import DigitalInOut, Direction, Pull
from analogio import AnalogIn
import adafruit_dotstar as dotstar
from simpleio import map_range, tone

# Red Status LED
led = DigitalInOut(board.LED_STATUS)
led.direction = Direction.OUTPUT
led.value = False

# The RGB LED
dot = dotstar.DotStar(board.DOTSTAR_CI, board.DOTSTAR_DI, 1, brightness=0.1)
dot[0] = (128, 0, 128)  # yellow startup status

import busio

try:
    stemma = busio.I2C(board.SCL, board.SDA)
    stemma_connected = True
    print("STEMMA DEVICE CONNECTED")
except:
    stemma_connected = False
    print("Stemma device disconnected")
    time.sleep(3)

# Analog input on VOLTAGE_MONITOR
Beispiel #7
0
# so we need to reset the Music Maker after Linux is booted
# Rework Instructions:
# 1. Cut Reset pad (https://learn.adafruit.com/adafruit-music-maker-featherwing/pinouts#reset-jumper-and-pad-2992586-25)
#   1a. Reset line is normally connected to System reset which would cause the whole System to reset
# 2. Solder wire from RST via to adjacent pad (AD4)
#   2a. When looking at the bottom, there's a Via under the "f" in feather and connects to the via under the first "e" in feather
# 3. Apply solder jumper on MIDI jumper
#   3a. https://learn.adafruit.com/adafruit-music-maker-featherwing/midi-synth#solder-closed-midi-jumper-2292069-2

# reset the chip using General Purpose I/O
import board
from digitalio import DigitalInOut, Direction

reset = DigitalInOut(board.AD4)
reset.direction = Direction.OUTPUT
reset.value = False
sleep(0.01)
reset.value = True
sleep(0.01)

import serial

# MIDI uses baud rate 31250 KBaud
VS1053_MIDI = serial.Serial('/dev/ttyS0', baudrate=31250)

# Now convert player_miditest.ino to Python
# https://github.com/adafruit/Adafruit_VS1053_Library/blob/master/examples/player_miditest/player_miditest.ino

# See http://www.vlsi.fi/fileadmin/datasheets/vs1053.pdf Pg 31
VS1053_BANK_DEFAULT = 0x00
VS1053_BANK_DRUMS1 = 0x78
Beispiel #8
0
        #     sendMeasurement(str(getTemp(temp1)))
        elif command == COMMAND_DICT['temp2']:
            sendMeasurement(str(temp2Value))

        elif command == COMMAND_DICT['set-current']:
            MODE = 'current'
            targetCurrent = int.from_bytes(uart.read(header), 'big') / 1000

            output = int(targetCurrent * 2**16 * 14.7 / 5 / 3.3)
            print("Set current to {}".format(targetCurrent))
        elif command == COMMAND_DICT['set-power']:
            MODE = 'power'
            targetPower = int.from_bytes(uart.read(header), 'big') / 1000
    else:

        if watchdog > 10:
            print("Watchdog")
            targetCurrent = 0
        else:
            watchdog += 1

    if battValue > 0.1:
        faultLed.value = False
        if MODE == 'power':
            targetCurrent = targetPower / battValue
        error = int((targetCurrent - currentValue) * 2**16 / 3.3)
        output += error // 4
        mos.value = min(max(output, 0), 2**16 - 1)
    else:
        faultLed.value = True
Beispiel #9
0
import pulseio
import pwmio
from digitalio import DigitalInOut, Direction, Pull
# pylint: disable=eval-used
# 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 = True
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 = pwmio.PWMOut(board.REMOTEOUT, frequency=38000,
                     duty_cycle=2 ** 15, variable_frequency=True)
pulse = pulseio.PulseOut(pwm)
Beispiel #10
0
greenLed = DigitalInOut(board.A2)
greenLed.direction = Direction.OUTPUT
yellowLed = DigitalInOut(board.A1)
yellowLed.direction = Direction.OUTPUT

while True:
    audio.play(wave)
    audio.pause()
    t = time.monotonic()
    while time.monotonic(
    ) - t < 2:  #plays for 2 seconds once x is above the threshold below
        x, y, z = [
            value / lis3d_sh.STANDARD_GRAVITY
            for value in accelerometer.acceleration
        ]
        print("x = %0.3f G, y = %0.3f G, z = %0.3f G" % (x, y, z))
        if x > 0.1:
            redLed.value = True
        else:
            redLed.value = False
        if x > 0.2:
            greenLed.value = True
        else:
            greenLed.value = False
        if x > 0.3:
            yellowLed.value = True
            audio.resume()
        else:
            yellowLed.value = False
            audio.pause
Beispiel #11
0
def button2Down():
	if not shortDelay(delayTime=0.01):
		cc.send(ConsumerControlCode.SCAN_PREVIOUS_TRACK)



button1Pin = DigitalInOut(board.D0)
button1Pin.direction = Direction.OUTPUT

button2Pin = DigitalInOut(board.D1)
button2Pin.direction = Direction.OUTPUT

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

Encoder = Encoder(board.D4, board.D3, upCallback=rotatedUp, downCallback=rotatedDown)

while True:
	Encoder.update()
	# Btn 1
	button1Pin.value = True
	if buttonInPin.value:
		button1Down()
	button1Pin.value = False
	# Btn 2
	button2Pin.value = True
	if buttonInPin.value:
		button2Down()
	button2Pin.value = False
Beispiel #12
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
MIRROR_OFFSET = (0, 0)
START_THRESHOLD = 20
TIMED_WAVE_STOP = 5000
POWER = (128, 128, 128, 128)

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

xshut_left = DigitalInOut(board.D1)
xshut_left.direction = Direction.OUTPUT
xshut_right = DigitalInOut(board.D3)
xshut_right.direction = Direction.OUTPUT
pixels = DigitalInOut(board.D4)
pixels.direction = Direction.OUTPUT

# Reset all the sensors
xshut_left.value = False
xshut_right.value = False
time.sleep(.01)
xshut_left.value = True
xshut_right.value = True
time.sleep(.01)

# Initialize the sensors one at a time so we can assign them different addresses
xshut_right.value = False
sensor_left = adafruit_vl53l0x.VL53L0X(i2c, I2C_ADDRESS_LEFT, TIMEOUT)
xshut_right.value = True
sensor_right = adafruit_vl53l0x.VL53L0X(i2c, I2C_ADDRESS_RIGHT, TIMEOUT)

# change read time
sensor_left.measurement_timing_budget = READ_TIME
sensor_right.measurement_timing_budget = READ_TIME
Beispiel #14
0
# CUSTOMISE SENSITIVITY HERE: smaller numbers = more sensitive to motion
HIT_THRESHOLD = 250
SWING_THRESHOLD = 150

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

#  NeoPixel setup
NUM_PIXELS = 34  # Number of pixels used in project
NEOPIXEL_PIN = board.D5
POWER_PIN = board.D10

enable = DigitalInOut(POWER_PIN)
enable.direction = Direction.OUTPUT
enable.value = False

strip = neopixel.NeoPixel(NEOPIXEL_PIN,
                          NUM_PIXELS,
                          brightness=.5,
                          auto_write=False)
strip.fill(0)  # NeoPixels off ASAP on startup
strip.show()

#  default NeoPixel color is white
COLOR = (255, 255, 255)

#  NeoPixel animations
pulse = Pulse(strip, speed=0.05, color=COLOR, period=3)
solid = Solid(strip, color=COLOR)
comet = Comet(strip, speed=0.05, color=COLOR, tail_length=40)
Beispiel #15
0
blinkInterval = 0.5
blinkTime = time.monotonic() + blinkInterval

# loop forever
while True:
    # gather inputs

    # see if the button has changed
    if button.value != buttonPre:
        # reset the previous value
        buttonPre = button.value
        if button.value:
            ledMode += 1
            if ledMode > 1:
                ledMode = 0

    # do output based on mode
    if ledMode == 1:
        # is it time to toggle the led?
        if time.monotonic() >= blinkTime:
            # blink
            print("blink")
            # toggle led value
            led.value = not led.value
            # increment the blinkTime
            blinkTime += blinkInterval

    else:
        led.value = False
        blinkTime = time.monotonic()
 clkState = GPIO.input(clk)
 dtState = GPIO.input(dt)
 if clkState != clkLastState:
     if dtState != clkState:
         mode += 1
         if mode == 1:
             print("You are on mode " + str(mode) + ". Click the Touch Module to Continue")
             if pad.value:
                 print("Words")
                 sleep(3)
                 print("Cat")
                 sleep(3)
                 print("Bat")
                 sleep(3)
                 print("Dog")
                 pad.value = False
         elif mode == 2:
             print("You are on mode " + str(mode) + ". Click the Touch Module to Continue")
             if pad.value:
                 print("Letters")
                 sleep(3)
                 print("A")
                 sleep(3)
                 print("B")
                 sleep(3)
                 print("C")
                 pad.value = False
         elif mode == 3:
             print("You are on mode " + str(mode) + ". Click the Touch Module to Continue")
             if pad.value:
                 print("Numbers")
Beispiel #17
0
            time.sleep(0.040)
            index = index + 4
    if direction < 0:
        index = 100
        while index >= 50:
            servos[0].angle = index
            time.sleep(0.040)
            index = index - 4
    time.sleep(0.020)


print("Its Stumble Bot Time")

while True:
    if button_A.value:  # If button A is pressed, start bot
        led.value = True  # Turn on LED 13 to show we're gone!
        for i in range(5):
            print("back 1")
            servo_back(1)
            time.sleep(0.100)
            print("front 1")
            servo_front(1)
            time.sleep(0.100)
            print("back 2")
            servo_back(-1)
            time.sleep(0.100)
            print("front 2")
            servo_front(-1)
            time.sleep(0.100)
        led.value = False
    # end if
Beispiel #18
0
import board
import busio
from digitalio import DigitalInOut, Direction

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
csag = DigitalInOut(board.D5)
csag.direction = Direction.OUTPUT
csag.value = True
csm = DigitalInOut(board.D6)
csm.direction = Direction.OUTPUT
csm.value = True

sensor = adafruit_lsm9ds1.LSM9DS1_SPI(spi, csag, csm)

sensor.accel_range = adafruit_lsm9ds1.ACCELRANGE_4G
sensor.mag_gain = adafruit_lsm9ds1.MAGGAIN_8GAUSS
sensor.gyro_scale = adafruit_lsm9ds1.GYROSCALE_500DP

while True:
    # Read acceleration, magnetometer, gyroscope, temperature.
    accel_x, accel_y, accel_z = sensor.acceleration
    mag_x, mag_y, mag_z = sensor.magnetic
    gyro_x, gyro_y, gyro_z = sensor.gyro
    temp = sensor.temperature
    # Print values.
    print('Acceleration (m/s^2): ({0:0.3f},{1:0.3f},{2:0.3f})'.format(
        accel_x, accel_y, accel_z))
    print('Magnetometer (gauss): ({0:0.3f},{1:0.3f},{2:0.3f})'.format(
        mag_x, mag_y, mag_z))
    print('Gyroscope (degrees/sec): ({0:0.3f},{1:0.3f},{2:0.3f})'.format(
        gyro_x, gyro_y, gyro_z))
# Screaming Cauldron
# for Adafruit Industries Learning Guide

from digitalio import DigitalInOut, Direction
from analogio import AnalogIn
import neopixel
import board
import time

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

aFXPin = DigitalInOut(board.D2)  # pin used to drive the AudioFX board
aFXPin.direction = Direction.OUTPUT

aFXPin.value = False  # runs once at startup
time.sleep(.1)  # pause a moment
aFXPin.value = True  # then turn it off

analog0in = AnalogIn(board.D1)
neoPin = board.D0  # pin int0 which the NeoPixels are plugged
numPix = 30  # number of NeoPixels
pixels = neopixel.NeoPixel(neoPin, numPix, auto_write=0, brightness=.8)
pixels.fill((
    0,
    0,
    0,
))
pixels.show()

Beispiel #20
0
button_1 = DigitalInOut(board.BUTTON_A)
button_1.switch_to_input(pull=Pull.DOWN)

# feed button
button_feed = DigitalInOut(board.A1)
button_feed.direction = Direction.INPUT
button_feed.pull = Pull.UP

# motor controller
motor = DigitalInOut(board.A2)
motor.direction = Direction.OUTPUT

# enable audio speaker
speaker = DigitalInOut(board.SPEAKER_ENABLE)
speaker.direction = Direction.OUTPUT
speaker.value = True

# blink all neopixels red 3 times
def errorBlink():
    for i in range(3):
        pixels.fill(RED)
        pixels.show()
        sleep(0.1)
        pixels.fill(OFF)
        pixels.show()
        sleep(0.1)

# runs motor for 'duration' (in seconds) then turns off motor
def runMotor(duration):
    motor.value = True
    pixels.fill(BLUE)
Beispiel #21
0
# Create an instance of the Adafruit IO REST client
io = RESTClient(aio_username, aio_key, wifi)

try:
    # Get the 'digital' feed from Adafruit IO
    digital_feed = io.get_feed('digital')
except AdafruitIO_RequestError:
    # If no 'digital' feed exists, create one
    digital_feed = io.create_new_feed('digital')

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

while True:
    # Get data from 'digital' feed
    print('getting data from IO...')
    feed_data = io.receive_data(digital_feed['key'])

    # Check if data is ON or OFF
    if int(feed_data['value']) == 1:
        print('received <- ON\n')
    elif int(feed_data['value']) == 0:
        print('received <= OFF\n')

    # Set the LED to the feed value
    LED.value = int(feed_data['value'])

    time.sleep(5)
Beispiel #22
0
from digitalio import DigitalInOut, Direction

# button access
import busio
from adafruit_bus_device.i2c_device import I2CDevice

# midi comms
import usb_midi
import adafruit_midi
from adafruit_midi.note_on import NoteOn
from adafruit_midi.note_off import NoteOff

# led setup
cs = DigitalInOut(board.GP17)
cs.direction = Direction.OUTPUT
cs.value = 0
pixels = adafruit_dotstar.DotStar(board.GP18,
                                  board.GP19,
                                  16,
                                  brightness=0.5,
                                  auto_write=True)

# button setup
i2c = busio.I2C(board.GP5, board.GP4)
device = I2CDevice(i2c, 0x20)

# midi setup
midi = adafruit_midi.MIDI(midi_out=usb_midi.ports[1], out_channel=9)


# enums
# 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

# With a Particle Argon
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")
esp = adafruit_espatcontrol.ESP_ATcontrol(uart,
                                          115200,
                                          reset_pin=resetpin,
                                          rts_pin=rtspin,
                                          debug=False)
print("Resetting ESP module")
esp.hard_reset()

first_pass = True
while True:
    try:
        if first_pass:
            print("Scanning for AP's")
_MICROSTEPS_PER_REV = const(_MICROSTEPS * _STEPS // 2)
_MICROSTEPS_PER_CYCLE = const(_MICROSTEPS * 2)


def _pwm_for_microstep(ms):
    x = math.cos(4 * math.pi * ms / _MICROSTEPS_PER_CYCLE)
    return int((x + 1) * (_PWM_MAX // 2))


_PWM_TABLE = [_pwm_for_microstep(ms) for ms in range(_MICROSTEPS_PER_CYCLE)]

# Use the LED to indicate when the coils are energised.
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT
led.value = True

# Bipolar stepper -- the two coils are A0-A1 and B0-B1.
pin_a0 = DigitalInOut(board.D8)
pin_a0.direction = Direction.OUTPUT
pin_a1 = DigitalInOut(board.D7)
pin_a1.direction = Direction.OUTPUT
pin_b0 = DigitalInOut(board.D5)
pin_b0.direction = Direction.OUTPUT
pin_b1 = DigitalInOut(board.D6)
pin_b1.direction = Direction.OUTPUT

# The h-bridge takes a PWM input, one for each of A and B.
pin_pwm_a = PWMOut(board.D9, frequency=200000, duty_cycle=0)
pin_pwm_b = PWMOut(board.D4, frequency=200000, duty_cycle=0)
Beispiel #25
0
        espfirmware += "{:c}".format(_)
print("ESP32 Firmware:", espfirmware)

print("ESP32 MAC:      {5:02X}:{4:02X}:{3:02X}:{2:02X}:{1:02X}:{0:02X}".format(
    *esp.MAC_address))

# initial digital write values
m4_d_w_val = False
esp_d_w_val = False

while True:
    print("\nESP32 DIGITAL:")

    # ESP32 digital read
    try:
        M4_D_W_PIN.value = m4_d_w_val
        print("M4 wrote:", m4_d_w_val, end=" ")
        # b/c ESP32 might have reset out from under us
        esp_init_pin_modes(ESP_D_R_PIN, ESP_D_W_PIN)
        esp_d_r_val = esp.set_digital_read(ESP_D_R_PIN)
        print("--> ESP read:", esp_d_r_val)
    except (RuntimeError, AssertionError) as e:
        print("ESP32 Error", e)
        esp_reset_all()

    # ESP32 digital write
    try:
        # b/c ESP32 might have reset out from under us
        esp_init_pin_modes(ESP_D_R_PIN, ESP_D_W_PIN)
        esp.set_digital_write(ESP_D_W_PIN, esp_d_w_val)
        print("ESP wrote:", esp_d_w_val, "--> Red LED")
import time
import board
from digitalio import DigitalInOut, Direction

# CircuitPython for Pico maps LED to GPIO25
led = DigitalInOut(board.LED)
led.direction = Direction.OUTPUT

while True:
    led.value = not led.value
    time.sleep(1)
Beispiel #27
0
        return [0, int(pos * 3), int(255 - pos * 3)]


######################### MAIN LOOP ##############################

i = 0
seen = False
while True:
    # spin internal LED around!
    dot[0] = wheel(i)
    dot.show()
    data = uart.read(32)
    if i % 10 is 0:
        seen = False
    if data is not None:
        seen = True
    # use A0 as capacitive touch to turn on internal LED
    if touch_in.value:
        uart.write(arr_on)
        print(arr_on)
    else:
        uart.write(arr_off)
        print(arr_off)
        # optional! uncomment below & save to have it sent a keypress
        # keyboard.press(Keycode.A)
        # keyboard.release_all()
    # uart.write(seen.encode("utf-8"))
    led.value = seen

    i = (i + 1) % 256  # run from 0 to 255
Beispiel #28
0
#  effect: type of vibration
#  delay: time between vibrations
def vibe(num_zzz, effect, delay):
    drv.sequence[0] = adafruit_drv2605.Effect(effect)
    for _ in range(0, num_zzz):
        drv.play()  # play the effect
        time.sleep(delay)  # for 0.5 seconds
        drv.stop()


#  start BLE
ble.start_advertising(advertisement)

while True:

    blue_led.value = False
    print("Waiting for connection")

    #  NeoPixel is red when not connected to BLE
    while not ble.connected:
        blue_led.value = False
        pixel.fill(color.RED)
        pixel.show()
    print("Connected")

    while ble.connected:
        blue_led.value = True  #  blue LED is on when connected
        all_ids.clear()
        for connection in ble.connections:
            if not connection.paired:
                #  pairs to phone
Beispiel #29
0
import random
import time

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

SAMPLERATE = 8000
START_COUNT = 4

pixels = neopixel.NeoPixel(board.NEOPIXEL, 10, brightness=.2)
spkrenable = DigitalInOut(board.SPEAKER_ENABLE)
spkrenable.direction = Direction.OUTPUT
spkrenable.value = True


# Yoinked this from another example
def create_sample(frequency):
    length = SAMPLERATE // frequency
    sine_wave = array.array("H", [0] * int(length))
    for i in range(length):
        sine_wave[i] = int(math.sin(math.pi * 2 * i / 18) * (2**15) + 2**15)
    sample = audioio.AudioOut(board.SPEAKER, sine_wave)
    # Mismatch is intentional...weird API?
    sample.frequency = SAMPLERATE
    return sample


def clear():
# use the slide switch to turn blink on or off

# import modules and libraries
import board
from digitalio import DigitalInOut, Direction, Pull
import time

# declare variables and objects

# declare led digitalio object and set its direction
led = DigitalInOut(board.D13)
led.direction = Direction.OUTPUT

# declare switch digitalio object, set direction and pull
switch = DigitalInOut(board.D7)
switch.direction = Direction.INPUT
switch.pull = Pull.UP

# repeat this code forever
while True:

    print(switch.value)
    led.value = switch.value

    time.sleep(0.1)
Beispiel #31
0
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)
pulse = pulseio.PulseOut(pwm)