It's easy to use the features of the Slider Trinkey with Arduino. You can use the potentiometer, the NeoPixels and the capacitive touch pad.
Required Libraries
You'll need two libraries for this example: Adafruit NeoPixel and Adafruit FreeTouch.
Open the Arduino Library manager.
Search for NeoPixel and install Adafruit NeoPixel, being sure to double check the name.
Search for FreeTouch, and install Adafruit FreeTouch.
// SPDX-FileCopyrightText: 2021 Kattni Rembor for Adafruit Industries // // SPDX-License-Identifier: MIT #include <Adafruit_NeoPixel.h> #include "Adafruit_FreeTouch.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); // Create the touch pad Adafruit_FreeTouch qt = Adafruit_FreeTouch(PIN_TOUCH, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE); int16_t neo_brightness = 255; // initialize with highest brightness void setup() { Serial.begin(9600); //while (!Serial); strip.begin(); strip.setBrightness(neo_brightness); strip.show(); // Initialize all pixels to 'off' analogReadResolution(12); // set highest resolution if (! qt.begin()) Serial.println("Failed to begin qt"); } void loop() { uint16_t touch = qt.measure(); Serial.print("Touch: "); Serial.println(touch); uint16_t potval = analogRead(PIN_POTENTIOMETER); Serial.print("Slider: "); Serial.println((float)potval / 4095); uint8_t wheelval = map(potval, 0, 4095, 0, 255); //Serial.print("Wheel: "); //Serial.println(wheelval); // If the pad is touched, turn off neopix! if (touch > 500) { Serial.println("Touched!"); strip.setBrightness(0); } else { strip.setBrightness(255); } for(int i=0; i< strip.numPixels(); i++) { strip.setPixelColor(i, Wheel((wheelval+85) % 255)); } strip.show(); 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); } }
Slide the potentiometer back and forth to change the NeoPixel color. Touch the pad to turn off the NeoPixels while you touch it.
You can open the serial monitor to see the potentiometer and touch pad values printed out.
That's all there is to using the Slider Trinkey with Arduino!
Text editor powered by tinymce.