You can use the JST SH plug on the Pixel Trinkey to add a digital input. To do this with Arduino involves wiring up a button to the JST SH input on the Trinkey, installing the Adafruit_NeoPixel library and running the provided example code.
You can use the JST SH connector to wire up a button.
- Button input to JST SH D4 (white wire)
- Button GND to JST SH GND (black wire)
For this example, the built-in NeoPixel will be used.
Library Installation
You can install the Adafruit NeoPixel library for Arduino using the Library Manager in the Arduino IDE.
Click the Manage Libraries ... menu item, search for Adafruit NeoPixel, and select the Adafruit NeoPixel library:
There are no additional dependencies for the Adafruit NeoPixel library.
// SPDX-FileCopyrightText: 2024 ladyada for Adafruit Industries // // SPDX-License-Identifier: MIT #include <Adafruit_NeoPixel.h> Adafruit_NeoPixel pixel(1, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800); const int buttonPin = MISO; int buttonState = 0; void setup() { Serial.begin(115200); pinMode(buttonPin, INPUT); pixel.begin(); pixel.setBrightness(10); pixel.show(); } void loop() { buttonState = digitalRead(buttonPin); if (buttonState == HIGH) { pixel.setPixelColor(0, 0x0); pixel.show(); } else { pixel.setPixelColor(0, 0xFF0000); pixel.show(); } delay(100); }
Upload the sketch to your board. When you press the button, the onboard NeoPixel will light up red. When you release the button, the NeoPixel will turn off.
Text editor powered by tinymce.