Skip to content

Commit e0a0722

Browse files
authored
Merge pull request #2414 from adafruit/neokey_bff
adding example code for neokey bff
2 parents fa4f6b1 + 7f8d65c commit e0a0722

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

NeoKey_BFF_Examples/Arduino_NeoKey_Example/.feather_rp2040.test.only

Whitespace-only changes.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// SPDX-FileCopyrightText: 2023 Liz Clark for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
// Basic Keyboard Example for NeoKey BFF
6+
7+
#include <Keyboard.h>
8+
#include <Adafruit_NeoPixel.h>
9+
10+
#define LED_PIN A3
11+
#define MX_PIN A2
12+
#define LED_COUNT 1
13+
14+
int mxState = 0;
15+
16+
Adafruit_NeoPixel pixel(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
17+
18+
void setup() {
19+
Serial.begin(115200);
20+
Keyboard.begin();
21+
delay(5000);
22+
pinMode(MX_PIN, INPUT);
23+
pixel.begin();
24+
pixel.show();
25+
pixel.setBrightness(50);
26+
}
27+
28+
void loop() {
29+
mxState = digitalRead(MX_PIN);
30+
31+
if(mxState == HIGH) {
32+
pixel.setPixelColor(0, pixel.Color(150, 0, 0));
33+
pixel.show();
34+
Keyboard.print("Hello World!");
35+
}
36+
37+
if(mxState == LOW) {
38+
pixel.setPixelColor(0, pixel.Color(0, 0, 0));
39+
pixel.show();
40+
}
41+
42+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
# SPDX-FileCopyrightText: 2023 Liz Clark for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""Basic HID Macro with NeoKey BFF Example"""
6+
import time
7+
import board
8+
from digitalio import DigitalInOut, Direction, Pull
9+
import neopixel
10+
import usb_hid
11+
from adafruit_hid.keyboard import Keyboard
12+
from adafruit_hid.keycode import Keycode
13+
14+
# setup onboard NeoPixel
15+
pixel_pin = board.A3
16+
num_pixels = 1
17+
pixel_color = (0, 255, 0)
18+
off = (0, 0, 0)
19+
20+
pixels = neopixel.NeoPixel(pixel_pin, num_pixels, brightness=0.3, auto_write=False)
21+
22+
# The Keycode sent for each button, will be paired with a control key
23+
key = Keycode.F
24+
modifier_key = Keycode.CONTROL
25+
26+
# The keyboard object!
27+
time.sleep(1) # Sleep for a bit to avoid a race condition on some systems
28+
keyboard = Keyboard(usb_hid.devices)
29+
30+
# setup onboard button
31+
switch = DigitalInOut(board.A2)
32+
switch.direction = Direction.INPUT
33+
switch.pull = Pull.UP
34+
switch_state = False
35+
36+
while True:
37+
38+
# if the button is not pressed..
39+
if switch.value and switch_state:
40+
pixels.fill(off)
41+
pixels.show()
42+
keyboard.release_all()
43+
switch_state = False
44+
45+
# if the button is pressed..
46+
if not switch.value and not switch_state:
47+
# neopixel brightness is 0.3 and rainbow animation is visible
48+
pixels.fill(pixel_color)
49+
pixels.show()
50+
keyboard.press(modifier_key, key)
51+
switch_state = True

0 commit comments

Comments
 (0)