/ CPX_GBoard / universal / code.py
code.py
  1  # SPDX-FileCopyrightText: 2018 Dave Astels for Adafruit Industries
  2  #
  3  # SPDX-License-Identifier: MIT
  4  
  5  """
  6  Circuit Playground Express GBoard: universal/customizable version
  7  
  8  Adafruit invests time and resources providing this open source code.
  9  Please support Adafruit and open source hardware by purchasing
 10  products from Adafruit!
 11  
 12  Written by Dave Astels for Adafruit Industries
 13  Copyright (c) 2018 Adafruit Industries
 14  Licensed under the MIT license.
 15  
 16  All text above must be included in any redistribution.
 17  """
 18  # pylint: disable=unused-import
 19  
 20  import time
 21  from adafruit_circuitplayground.express import cpx
 22  
 23  # Uncomment the next 2 lines if you want to use external buttons
 24  # from digitalio import DigitalInOut, Direction, Pull
 25  # import board
 26  
 27  # Uncomment the next 3 lines if you want to use HID output
 28  # from adafruit_hid.keyboard import Keyboard
 29  # from adafruit_hid.keycode import Keycode
 30  # import usb_hid
 31  
 32  DOT_DURATION = 0.20
 33  DASH_DURATION = 0.5
 34  
 35  # You can adjust this to get the level of sensitivity you want.
 36  # Uncomment the next line if you want to use capacitive touch.
 37  # cpx.adjust_touch_threshold(100)
 38  
 39  # Uncomment the next 6 lines if you want to use external buttons
 40  # button_a = DigitalInOut(board.A4)
 41  # button_a.direction = Direction.INPUT
 42  # button_a.pull = Pull.UP
 43  # button_b = DigitalInOut(board.A3)
 44  # button_b.direction = Direction.INPUT
 45  # button_b.pull = Pull.UP
 46  
 47  # Uncomment the next  line if you want to use HID output
 48  # kbd = Keyboard(usb_hid.devices)
 49  
 50  
 51  
 52  def touch_a():
 53      # Uncomment the next line if you want to use the on-board buttons
 54      # return cpx.button_a
 55  
 56      # Uncomment the next line if you want to use capacitive touch
 57      # return cpx.touch_A4
 58  
 59      # Uncomment the next line if you want to use external buttons
 60      # return not button_a.value
 61  
 62      return False   # a fail-safe to keep python happy
 63  
 64  
 65  def touch_b():
 66      # Uncomment the next line if you want to use the on-board buttons
 67      # return cpx.button_b
 68  
 69      # Uncomment the next line if you want to use capacitive touch
 70      # return cpx.touch_A3
 71  
 72      # Uncomment the next line if you want to use external buttons
 73      # return not button_b.value
 74  
 75      return False   # a fail-safe to keep python happy
 76  
 77  
 78  def dot():
 79      # Uncomment the next 2 lines if you want tones played
 80      # cpx.play_tone(4000, DOT_DURATION)
 81      # time.sleep(0.1)
 82  
 83      # Uncomment the next line if you want to use HID output
 84      # kbd.send(Keycode.PERIOD)
 85  
 86      pass   # a fail-safe to keep python happy
 87  
 88  
 89  def dash():
 90      # Uncomment the next 2 lines if you want tones played
 91      # cpx.play_tone(4000, DASH_DURATION)
 92      # time.sleep(0.1)
 93  
 94      # Uncomment the next line if you want to use HID output
 95      # kbd.send(Keycode.MINUS)
 96  
 97      pass   # a fail-safe to keep python happy
 98  
 99  
100  while True:
101      if touch_a():
102          dot()
103          while touch_a():
104              pass
105      elif touch_b():
106          dash()
107          while touch_b():
108              pass