code.py
 1  # SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries
 2  #
 3  # SPDX-License-Identifier: MIT
 4  
 5  """
 6  Proximity spacebar dino game example. Sends a space when you move your hand close to the proximity
 7  sensor and turns the LEDs on to let you know you're in the right range. For use with the Chrome
 8  Dino game, reachable in Chrome with chrome://dino or when you have no network connectivity.
 9  """
10  import board
11  import usb_hid
12  from adafruit_hid.keyboard import Keyboard
13  from adafruit_hid.keycode import Keycode
14  import neopixel
15  from adafruit_apds9960.apds9960 import APDS9960
16  
17  apds = APDS9960(board.I2C())
18  pixels = neopixel.NeoPixel(board.NEOPIXEL, 2)
19  keyboard = Keyboard(usb_hid.devices)
20  
21  apds.enable_proximity = True
22  
23  space = False
24  while True:
25      print(apds.proximity)
26      current_proximity = apds.proximity
27      if current_proximity > 100 and not space:
28          pixels.fill((255, 0, 0))
29          keyboard.send(Keycode.SPACE)
30          space = True
31      elif current_proximity < 50 and space:
32          pixels.fill(0)
33          space = False