Adding Prox Trinkey code
This commit is contained in:
parent
cb920b224f
commit
74201d5458
7 changed files with 205 additions and 0 deletions
13
Adafruit_Proximity_Trinkey/Capacitive_Touch_One_Pad/code.py
Normal file
13
Adafruit_Proximity_Trinkey/Capacitive_Touch_One_Pad/code.py
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
"""
|
||||
CircuitPython Capacitive Touch Pad Example - Print to the serial console when one pad is touched.
|
||||
"""
|
||||
import time
|
||||
import board
|
||||
import touchio
|
||||
|
||||
touch = touchio.TouchIn(board.TOUCH1)
|
||||
|
||||
while True:
|
||||
if touch.value:
|
||||
print("Pad touched!")
|
||||
time.sleep(0.1)
|
||||
16
Adafruit_Proximity_Trinkey/Capacitive_Touch_Two_Pad/code.py
Normal file
16
Adafruit_Proximity_Trinkey/Capacitive_Touch_Two_Pad/code.py
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
"""
|
||||
CircuitPython Capacitive Two Touch Pad Example - Print to the serial console when a pad is touched.
|
||||
"""
|
||||
import time
|
||||
import board
|
||||
import touchio
|
||||
|
||||
touch_one = touchio.TouchIn(board.TOUCH1)
|
||||
touch_two = touchio.TouchIn(board.TOUCH2)
|
||||
|
||||
while True:
|
||||
if touch_one.value:
|
||||
print("Pad one touched!")
|
||||
if touch_two.value:
|
||||
print("Pad two touched!")
|
||||
time.sleep(0.1)
|
||||
14
Adafruit_Proximity_Trinkey/NeoPixel_Blink/code.py
Normal file
14
Adafruit_Proximity_Trinkey/NeoPixel_Blink/code.py
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
"""
|
||||
CircuitPython NeoPixel Blink example - blinking the built-in NeoPixels.
|
||||
"""
|
||||
import time
|
||||
import board
|
||||
import neopixel
|
||||
|
||||
pixel = neopixel.NeoPixel(board.NEOPIXEL, 2)
|
||||
|
||||
while True:
|
||||
pixel.fill((255, 0, 0))
|
||||
time.sleep(0.5)
|
||||
pixel.fill((0, 0, 0))
|
||||
time.sleep(0.5)
|
||||
26
Adafruit_Proximity_Trinkey/NeoPixel_Brightness/code.py
Normal file
26
Adafruit_Proximity_Trinkey/NeoPixel_Brightness/code.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
"""
|
||||
NeoPixel brightness proximity example. Increases the brightness of the NeoPixels as you move closer
|
||||
to the proximity sensor.
|
||||
"""
|
||||
import time
|
||||
import board
|
||||
import neopixel
|
||||
from adafruit_apds9960.apds9960 import APDS9960
|
||||
|
||||
apds = APDS9960(board.I2C())
|
||||
pixels = neopixel.NeoPixel(board.NEOPIXEL, 2)
|
||||
|
||||
apds.enable_proximity = True
|
||||
|
||||
|
||||
def proximity_to_brightness(value):
|
||||
"""Maps the proximity values (0 - 255) to the brightness values (0.0 - 1.0)"""
|
||||
return value / 255 * 1.0
|
||||
|
||||
|
||||
pixels.fill((255, 0, 0))
|
||||
|
||||
while True:
|
||||
print(apds.proximity)
|
||||
pixels.brightness = proximity_to_brightness(apds.proximity)
|
||||
time.sleep(0.2)
|
||||
29
Adafruit_Proximity_Trinkey/Proximity_Spacebar_Game/code.py
Normal file
29
Adafruit_Proximity_Trinkey/Proximity_Spacebar_Game/code.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
"""
|
||||
Proximity spacebar dino game example. Sends a space when you move your hand close to the proximity
|
||||
sensor and turns the LEDs on to let you know you're in the right range. For use with the Chrome
|
||||
Dino game, reachable in Chrome with chrome://dino or when you have no network connectivity.
|
||||
"""
|
||||
import board
|
||||
import usb_hid
|
||||
from adafruit_hid.keyboard import Keyboard
|
||||
from adafruit_hid.keycode import Keycode
|
||||
import neopixel
|
||||
from adafruit_apds9960.apds9960 import APDS9960
|
||||
|
||||
apds = APDS9960(board.I2C())
|
||||
pixels = neopixel.NeoPixel(board.NEOPIXEL, 2)
|
||||
keyboard = Keyboard(usb_hid.devices)
|
||||
|
||||
apds.enable_proximity = True
|
||||
|
||||
space = False
|
||||
while True:
|
||||
print(apds.proximity)
|
||||
current_proximity = apds.proximity
|
||||
if current_proximity > 100 and not space:
|
||||
pixels.fill((255, 0, 0))
|
||||
keyboard.send(Keycode.SPACE)
|
||||
space = True
|
||||
elif current_proximity < 50 and space:
|
||||
pixels.fill(0)
|
||||
space = False
|
||||
|
|
@ -0,0 +1 @@
|
|||
|
||||
|
|
@ -0,0 +1,106 @@
|
|||
#include <Adafruit_NeoPixel.h>
|
||||
#include "Adafruit_FreeTouch.h"
|
||||
#include "Adafruit_APDS9960.h"
|
||||
|
||||
|
||||
// Create the neopixel strip with the built in definitions NUM_NEOPIXEL and PIN_NEOPIXEL
|
||||
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_NEOPIXEL, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
|
||||
int16_t neo_brightness = 20; // initialize with 20 brightness (out of 255)
|
||||
|
||||
// Create the two touch pads on pins 1 and 2:
|
||||
Adafruit_FreeTouch qt_1 = Adafruit_FreeTouch(1, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
|
||||
Adafruit_FreeTouch qt_2 = Adafruit_FreeTouch(2, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
|
||||
|
||||
Adafruit_APDS9960 apds;
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
//while (!Serial);
|
||||
|
||||
strip.begin();
|
||||
strip.setBrightness(neo_brightness);
|
||||
strip.show(); // Initialize all pixels to 'off'
|
||||
|
||||
if (! qt_1.begin())
|
||||
Serial.println("Failed to begin qt on pin 1");
|
||||
if (! qt_2.begin())
|
||||
Serial.println("Failed to begin qt on pin 2");
|
||||
|
||||
pinMode(PIN_INTERRUPT, INPUT_PULLUP);
|
||||
if(!apds.begin()){
|
||||
Serial.println("failed to initialize device! Please check your wiring.");
|
||||
while (1) {
|
||||
strip.fill(0xFF0000);
|
||||
strip.show();
|
||||
delay(100);
|
||||
strip.fill(0x00);
|
||||
strip.show();
|
||||
delay(100);
|
||||
}
|
||||
}
|
||||
|
||||
Serial.println("APDS initialized!");
|
||||
apds.enableProximity(true);
|
||||
apds.setProxGain(APDS9960_PGAIN_8X);
|
||||
apds.setLED(APDS9960_LEDDRIVE_100MA, APDS9960_LEDBOOST_300PCNT);
|
||||
apds.setProxPulse(APDS9960_PPULSELEN_16US, 1);
|
||||
|
||||
//set the interrupt threshold to fire when proximity reading goes above 2
|
||||
apds.setProximityInterruptThreshold(0, 2);
|
||||
apds.enableProximityInterrupt();
|
||||
}
|
||||
|
||||
uint8_t j=0;
|
||||
|
||||
void loop() {
|
||||
|
||||
// print the proximity reading when the interrupt pin goes low
|
||||
if (!digitalRead(PIN_INTERRUPT)){
|
||||
uint16_t prox = apds.readProximity();
|
||||
Serial.print("Proximity: ");
|
||||
Serial.println(prox);
|
||||
|
||||
if (prox < 3) prox = 0; // ignore 1 and 2 readings
|
||||
strip.setBrightness(prox);
|
||||
|
||||
//clear the interrupt
|
||||
apds.clearInterrupt();
|
||||
} else {
|
||||
strip.setBrightness(0);
|
||||
}
|
||||
|
||||
strip.fill(Wheel(j));
|
||||
strip.show();
|
||||
|
||||
// measure the captouches
|
||||
uint16_t touch1 = qt_1.measure();
|
||||
uint16_t touch2 = qt_2.measure();
|
||||
|
||||
// If the first pad is touched, go forward
|
||||
if (touch1 > 500) {
|
||||
Serial.println("QT 1 touched");
|
||||
j++;
|
||||
}
|
||||
|
||||
// If the second pad is touched, go backward
|
||||
if (touch2 > 500) {
|
||||
Serial.println("QT 2 touched");
|
||||
j--;
|
||||
}
|
||||
|
||||
delay(10);
|
||||
}
|
||||
|
||||
// Input a value 0 to 255 to get a color value.
|
||||
// The colours are a transition r - g - b - back to r.
|
||||
uint32_t Wheel(byte WheelPos) {
|
||||
if(WheelPos < 85) {
|
||||
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
|
||||
} else if(WheelPos < 170) {
|
||||
WheelPos -= 85;
|
||||
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
|
||||
} else {
|
||||
WheelPos -= 170;
|
||||
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue