Limited items in stock
View Purchasing OptionsThere are some really cool things you can do when you combine an electronics dev board with a Linux SoC! Today, I want to show you how easy it is to prototype with Piunora by making a sensor-based game controller. In the demo below, we are using Adafruit Blinka (a library that enables CircuitPython code on Linux) and an Adafruit VCNL4040 distance sensor attached by a single cable to Piunora’s Qwiic/Stemma-QT connector. No breadboards or soldering required!
For this demo, all I had to do is write a few lines of code to generate keypresses based on sensor input. That way you can build a controller that is compatible with existing games, such as the Chromium Dinosaur Game shown above. If you write your own games, you can achieve some really interesting game mechanics by integrating "analog" distance value directly.
Below is the code for this demo in its entirety. (I also control a NeoPixel to provide some visual indication as to how close my hand was to the sensor.)
import math
import time
import board
import busio
import adafruit_vcnl4040
import neopixel
import simpleio
import keyboard
pixels = neopixel.NeoPixel(board.D12, 1, brightness=0.2)
i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_vcnl4040.VCNL4040(i2c)
while True:
print("Proximity:", sensor.proximity)
pixels.fill((0, math.floor(simpleio.map_range(sensor.proximity,3,200,0,255)), 0))
if sensor.proximity > 6:
keyboard.press('space')
pass
else:
keyboard.release('space')