Skip to content

Commit 433d85a

Browse files
authored
Merge pull request #1611 from adafruit/neokey_emoji
Code for NeoKey emojis
2 parents 9a2f6f0 + 4905a0d commit 433d85a

2 files changed

Lines changed: 229 additions & 0 deletions

File tree

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
import time
2+
import board
3+
import busio
4+
from adafruit_neokey.neokey1x4 import NeoKey1x4
5+
import usb_hid
6+
from adafruit_hid.keyboard import Keyboard
7+
from adafruit_hid.keycode import Keycode
8+
9+
# use STEMMA I2C bus on RP2040 QT Py
10+
i2c_bus = busio.I2C(board.SCL1, board.SDA1)
11+
12+
# Create a NeoKey object
13+
neokey = NeoKey1x4(i2c_bus, addr=0x30)
14+
15+
# create a keyboard object
16+
keyboard = Keyboard(usb_hid.devices)
17+
18+
print("NeoKey Emoji keyboard - macOS")
19+
20+
# states for key presses
21+
key_0_state = False
22+
key_1_state = False
23+
key_2_state = False
24+
key_3_state = False
25+
26+
# update these arrays to customize your emojis
27+
# cat face emoji
28+
emoji_0 = [Keycode.C, Keycode.A, Keycode.T, Keycode.DOWN_ARROW, Keycode.ENTER]
29+
# lightning bolt emoji
30+
emoji_1 = [Keycode.V, Keycode.O, Keycode.L, Keycode.T, Keycode.DOWN_ARROW, Keycode.ENTER]
31+
# control panel emoji
32+
emoji_2 = [Keycode.C, Keycode.O, Keycode.N, Keycode.T, Keycode.R, Keycode.O,
33+
Keycode.DOWN_ARROW, Keycode.ENTER]
34+
# guitar emoji
35+
emoji_3 = [Keycode.G, Keycode.U, Keycode.I, Keycode.T, Keycode.DOWN_ARROW, Keycode.ENTER]
36+
37+
while True:
38+
# switch debouncing
39+
# also turns off NeoPixel on release
40+
if not neokey[0] and key_0_state:
41+
key_0_state = False
42+
neokey.pixels[0] = 0x0
43+
if not neokey[1] and key_1_state:
44+
key_1_state = False
45+
neokey.pixels[1] = 0x0
46+
if not neokey[2] and key_2_state:
47+
key_2_state = False
48+
neokey.pixels[2] = 0x0
49+
if not neokey[3] and key_3_state:
50+
key_3_state = False
51+
neokey.pixels[3] = 0x0
52+
53+
# if 1st neokey is pressed...
54+
if neokey[0] and not key_0_state:
55+
print("Button A")
56+
# turn on NeoPixel
57+
neokey.pixels[0] = 0xFF0000
58+
# open macOS emoji menu
59+
keyboard.send(Keycode.CONTROL, Keycode.COMMAND, Keycode.SPACE)
60+
# delay for opening menu
61+
time.sleep(.2)
62+
# send key presses for emoji_0
63+
for i in emoji_0:
64+
keyboard.send(i)
65+
time.sleep(0.05)
66+
# update key state
67+
key_0_state = True
68+
69+
# if 2nd neokey is pressed...
70+
if neokey[1] and not key_1_state:
71+
print("Button B")
72+
# turn on NeoPixel
73+
neokey.pixels[1] = 0xFFFF00
74+
# open macOS emoji menu
75+
keyboard.send(Keycode.CONTROL, Keycode.COMMAND, Keycode.SPACE)
76+
# delay for opening menu
77+
time.sleep(.2)
78+
# send key presses for emoji_1
79+
for i in emoji_1:
80+
keyboard.send(i)
81+
time.sleep(0.05)
82+
# update key state
83+
key_1_state = True
84+
85+
# if 3rd neokey is pressed...
86+
if neokey[2] and not key_2_state:
87+
print("Button C")
88+
# turn on NeoPixel
89+
neokey.pixels[2] = 0x00FF00
90+
# open macOS emoji menu
91+
keyboard.send(Keycode.CONTROL, Keycode.COMMAND, Keycode.SPACE)
92+
# delay for opening menu
93+
time.sleep(.2)
94+
# send key presses for emoji_2
95+
for i in emoji_2:
96+
keyboard.send(i)
97+
time.sleep(0.05)
98+
# update key state
99+
key_2_state = True
100+
101+
# if 4th neokey is pressed...
102+
if neokey[3] and not key_3_state:
103+
print("Button D")
104+
# turn on NeoPixel
105+
neokey.pixels[3] = 0x00FFFF
106+
# open macOS emoji menu
107+
keyboard.send(Keycode.CONTROL, Keycode.COMMAND, Keycode.SPACE)
108+
# delay for opening menu
109+
time.sleep(.2)
110+
# send key presses for emoji_3
111+
for i in emoji_3:
112+
keyboard.send(i)
113+
time.sleep(0.05)
114+
# update key state
115+
key_3_state = True
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
import time
2+
import board
3+
import busio
4+
from adafruit_neokey.neokey1x4 import NeoKey1x4
5+
import usb_hid
6+
from adafruit_hid.keyboard import Keyboard
7+
from adafruit_hid.keycode import Keycode
8+
9+
# use STEMMA I2C bus on RP2040 QT Py
10+
i2c_bus = busio.I2C(board.SCL1, board.SDA1)
11+
12+
# Create a NeoKey object
13+
neokey = NeoKey1x4(i2c_bus, addr=0x30)
14+
15+
# create a keyboard object
16+
keyboard = Keyboard(usb_hid.devices)
17+
18+
print("NeoKey Emoji keyboard - Windows")
19+
20+
# states for key presses
21+
key_0_state = False
22+
key_1_state = False
23+
key_2_state = False
24+
key_3_state = False
25+
26+
# update these arrays to customize your emojis
27+
# cat face emoji
28+
emoji_0 = [Keycode.C, Keycode.A, Keycode.T, Keycode.SPACE, Keycode.F, Keycode.ENTER, Keycode.ESCAPE]
29+
# lightning bolt emoji
30+
emoji_1 = [Keycode.V, Keycode.O, Keycode.L, Keycode.T, Keycode.ENTER, Keycode.ESCAPE]
31+
# control panel emoji
32+
emoji_2 = [Keycode.K, Keycode.N, Keycode.O, Keycode.ENTER, Keycode.ESCAPE]
33+
# guitar emoji
34+
emoji_3 = [Keycode.G, Keycode.U, Keycode.I, Keycode.T, Keycode.ENTER, Keycode.ESCAPE]
35+
36+
while True:
37+
# switch debouncing
38+
# also turns off NeoPixel on release
39+
if not neokey[0] and key_0_state:
40+
key_0_state = False
41+
neokey.pixels[0] = 0x0
42+
if not neokey[1] and key_1_state:
43+
key_1_state = False
44+
neokey.pixels[1] = 0x0
45+
if not neokey[2] and key_2_state:
46+
key_2_state = False
47+
neokey.pixels[2] = 0x0
48+
if not neokey[3] and key_3_state:
49+
key_3_state = False
50+
neokey.pixels[3] = 0x0
51+
52+
# if 1st neokey is pressed...
53+
if neokey[0] and not key_0_state:
54+
print("Button A")
55+
# turn on NeoPixel
56+
neokey.pixels[0] = 0xFF0000
57+
# open windows emoji menu
58+
keyboard.send(Keycode.WINDOWS, Keycode.PERIOD)
59+
# delay for opening menu
60+
time.sleep(0.75)
61+
# send key presses for emoji_0
62+
for i in emoji_0:
63+
keyboard.send(i)
64+
time.sleep(0.05)
65+
# update key state
66+
key_0_state = True
67+
68+
# if 2nd neokey is pressed...
69+
if neokey[1] and not key_1_state:
70+
print("Button B")
71+
# turn on NeoPixel
72+
neokey.pixels[1] = 0xFFFF00
73+
# open windows emoji menu
74+
keyboard.send(Keycode.WINDOWS, Keycode.PERIOD)
75+
# delay for opening menu
76+
time.sleep(.75)
77+
# send key presses for emoji_1
78+
for i in emoji_1:
79+
keyboard.send(i)
80+
time.sleep(0.05)
81+
# update key state
82+
key_1_state = True
83+
84+
# if 3rd neokey is pressed...
85+
if neokey[2] and not key_2_state:
86+
print("Button C")
87+
# turn on NeoPixel
88+
neokey.pixels[2] = 0x00FF00
89+
# open windows emoji menu
90+
keyboard.send(Keycode.WINDOWS, Keycode.PERIOD)
91+
# delay for opening menu
92+
time.sleep(.75)
93+
# send key presses for emoji_2
94+
for i in emoji_2:
95+
keyboard.send(i)
96+
time.sleep(0.05)
97+
# update key state
98+
key_2_state = True
99+
100+
# if 4th neokey is pressed...
101+
if neokey[3] and not key_3_state:
102+
print("Button D")
103+
# turn on NeoPixel
104+
neokey.pixels[3] = 0x00FFFF
105+
# open windows emoji menu
106+
keyboard.send(Keycode.WINDOWS, Keycode.PERIOD)
107+
# delay for opening menu
108+
time.sleep(.75)
109+
# send key presses for emoji_3
110+
for i in emoji_3:
111+
keyboard.send(i)
112+
time.sleep(0.05)
113+
# update key state
114+
key_3_state = True

0 commit comments

Comments
 (0)