Simple test

Ensure your device works with this simple test.

examples/neokey1x4_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3"""NeoKey simpletest."""
 4
 5import board
 6
 7from adafruit_neokey.neokey1x4 import NeoKey1x4
 8
 9# use default I2C bus
10i2c_bus = board.I2C()
11
12# Create a NeoKey object
13neokey = NeoKey1x4(i2c_bus, addr=0x30)
14
15print("Adafruit NeoKey simple test")
16
17# Check each button, if pressed, light up the matching neopixel!
18while True:
19    if neokey[0]:
20        print("Button A")
21        neokey.pixels[0] = 0xFF0000
22    else:
23        neokey.pixels[0] = 0x0
24
25    if neokey[1]:
26        print("Button B")
27        neokey.pixels[1] = 0xFFFF00
28    else:
29        neokey.pixels[1] = 0x0
30
31    if neokey[2]:
32        print("Button C")
33        neokey.pixels[2] = 0x00FF00
34    else:
35        neokey.pixels[2] = 0x0
36
37    if neokey[3]:
38        print("Button D")
39        neokey.pixels[3] = 0x00FFFF
40    else:
41        neokey.pixels[3] = 0x0