Merge cpx_gboard project

This commit is contained in:
Dave Astels 2018-07-19 19:36:36 -04:00
parent 215948d8a5
commit fb85ab14e7
5 changed files with 263 additions and 0 deletions

52
CPX_GBoard/arcade_hid.py Normal file
View file

@ -0,0 +1,52 @@
"""
Circuit Playground Express GBoard: arcade buttons generating keycodes
Adafruit invests time and resources providing this open source code.
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 time
import board
from adafruit_circuitplayground.express import cpx
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
from digitalio import DigitalInOut, Direction, Pull
DOT_DURATION = 0.25
DASH_DURATION = 0.5
button_a = DigitalInOut(board.A4)
button_a.direction = Direction.INPUT
button_a.pull = Pull.UP
button_b = DigitalInOut(board.A3)
button_b.direction = Direction.INPUT
button_b.pull = Pull.UP
kbd = Keyboard()
def touch_a():
return not button_a.value
def touch_b():
return not button_b.value
while True:
if touch_a():
kbd.send(Keycode.PERIOD)
while touch_a():
pass
elif touch_b():
kbd.send(Keycode.MINUS)
while touch_b():
pass

View file

@ -0,0 +1,31 @@
"""
Circuit Playground Express GBoard: onboard buttons generating tones
Adafruit invests time and resources providing this open source code.
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 time
from adafruit_circuitplayground.express import cpx
DOT_DURATION = 0.20
DASH_DURATION = 0.5
while True:
if cpx.button_a:
cpx.play_tone(4000, DOT_DURATION)
time.sleep(0.1)
while cpx.button_a:
pass
elif cpx.button_b:
cpx.play_tone(4000, DASH_DURATION)
time.sleep(0.1)
while cpx.button_b:
pass

39
CPX_GBoard/touch_beeps.py Normal file
View file

@ -0,0 +1,39 @@
"""
Circuit Playground Express GBoard: capacitive touch generating tones
Adafruit invests time and resources providing this open source code.
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 time
from adafruit_circuitplayground.express import cpx
DOT_DURATION = 0.20
DASH_DURATION = 0.5
cpx.adjust_touch_threshold(600)
def touch_a():
return cpx.touch_A4
def touch_b():
return cpx.touch_A3
while True:
if touch_a():
cpx.play_tone(4000, DOT_DURATION)
time.sleep(0.1)
while touch_a():
pass
elif touch_b():
cpx.play_tone(4000, DASH_DURATION)
time.sleep(0.1)
while touch_b():
pass

40
CPX_GBoard/touch_hid.py Normal file
View file

@ -0,0 +1,40 @@
"""
Circuit Playground Express GBoard: capacitive touch generating keycodes
Adafruit invests time and resources providing this open source code.
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 time
from adafruit_circuitplayground.express import cpx
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keycode import Keycode
DOT_DURATION = 0.25
DASH_DURATION = 0.5
kbd = Keyboard()
cpx.adjust_touch_threshold(600)
def touch_a():
return cpx.touch_A4
def touch_b():
return cpx.touch_A3
while True:
if touch_a():
kbd.send(Keycode.PERIOD)
while touch_a():
pass
elif touch_b():
kbd.send(Keycode.MINUS)
while touch_b():
pass

101
CPX_GBoard/universal.py Normal file
View file

@ -0,0 +1,101 @@
"""
Circuit Playground Express GBoard: universal/customizable version
Adafruit invests time and resources providing this open source code.
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 time
from adafruit_circuitplayground.express import cpx
# Uncomment the next 2 lines if you want to use external buttons
# from digitalio import DigitalInOut, Direction, Pull
# import board
# Uncomment the next 2 lines if you want to use HID output
# from adafruit_hid.keyboard import Keyboard
# from adafruit_hid.keycode import Keycode
DOT_DURATION = 0.20
DASH_DURATION = 0.5
# Uncomment the next line if you want to use capacitive touch.
# cpx.adjust_touch_threshold(600)
# Uncomment the next 6 lines if you want to use external buttons
# button_a = DigitalInOut(board.A4)
# button_a.direction = Direction.INPUT
# button_a.pull = Pull.UP
# button_b = DigitalInOut(board.A3)
# button_b.direction = Direction.INPUT
# button_b.pull = Pull.UP
# Uncomment the next line if you want to use HID output
# kbd = Keyboard()
def touch_a():
# Uncomment the next line if you want to use the on-board buttons
# return cpx.button_a
# Uncomment the next line if you want to use capacitive touch
# return cpx.touch_A4
# Uncomment the next line if you want to use external buttons
# return not button_a.value
return False # a fail-safe to keep python happy
def touch_b():
# Uncomment the next line if you want to use the on-board buttons
# return cpx.button_b
# Uncomment the next line if you want to use capacitive touch
# return cpx.touch_A3
# Uncomment the next line if you want to use external buttons
# return not button_b.value
return False # a fail-safe to keep python happy
def dot():
# Uncomment the next 2 lines if you want tones played
# cpx.play_tone(4000, DOT_DURATION)
# time.sleep(0.1)
# Uncomment the next line if you want to use HID output
# kbd.send(Keycode.PERIOD)
pass # a fail-safe to keep python happy
def dash():
# Uncomment the next 2 lines if you want tones played
# cpx.play_tone(4000, DASH_DURATION)
# time.sleep(0.1)
# Uncomment the next line if you want to use HID output
# kbd.send(Keycode.MINUS)
pass # a fail-safe to keep python happy
while True:
if touch_a():
dot()
while touch_a():
pass
elif touch_b():
dash()
while touch_b():
pass