/ Factory_Tests / NeoKey_Trinkey_FactoryTest / NeoKey_Trinkey_FactoryTest.ino
NeoKey_Trinkey_FactoryTest.ino
 1  // SPDX-FileCopyrightText: 2022 Limor Fried for Adafruit Industries
 2  //
 3  // SPDX-License-Identifier: MIT
 4  
 5  #include <Adafruit_NeoPixel.h>
 6  #include "Adafruit_FreeTouch.h"
 7  #include "HID-Project.h"  // https://github.com/NicoHood/HID
 8  
 9  // Create the neopixel strip with the built in definitions NUM_NEOPIXEL and PIN_NEOPIXEL
10  Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_NEOPIXEL, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
11  
12  // Create the touch pad
13  Adafruit_FreeTouch qt = Adafruit_FreeTouch(PIN_TOUCH, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
14  
15  int16_t neo_brightness = 255; // initialize with 20 brightness (out of 255)
16  
17  bool last_switch = true;
18  
19  void setup() {
20    Serial.begin(9600);
21    //while (!Serial);
22    strip.begin();
23    strip.setBrightness(neo_brightness);
24    strip.show(); // Initialize all pixels to 'off'
25  
26    if (! qt.begin())  
27      Serial.println("Failed to begin qt");
28  
29    pinMode(PIN_SWITCH, INPUT_PULLDOWN);
30  
31    // Sends a clean report to the host. This is important on any Arduino type.
32    Consumer.begin();
33  }
34  
35  uint8_t j=0;
36  void loop() {
37    // measure the captouches
38    uint16_t touch = qt.measure();
39    // don't print touch data constantly, only every 10 runs  
40    if (j % 10 == 0) {
41      Serial.print("Touch: "); Serial.println(touch);
42    }
43    
44    // If the pad is touched, turn on neopix!
45    if (touch > 500) {
46      Serial.println("Touched!");
47      //strip.setBrightness(neo_brightness);
48    } else {
49      //strip.setBrightness(0);
50    }
51  
52    // check mechswitch
53    bool curr_switch = digitalRead(PIN_SWITCH);
54    if (curr_switch != last_switch) {
55      if (curr_switch) {
56        Serial.println("Pressed");
57        Consumer.write(MEDIA_PLAY_PAUSE);
58      } else {
59        Serial.println("Released");
60      }
61      last_switch = curr_switch;
62    }
63  
64    
65    // cycles of all colors on wheel, only visible if cap it touched
66    strip.setPixelColor(0, Wheel(j++));
67    strip.show();
68  
69    delay(10);
70  }
71  
72  // Input a value 0 to 255 to get a color value.
73  // The colours are a transition r - g - b - back to r.
74  uint32_t Wheel(byte WheelPos) {
75    if(WheelPos < 85) {
76     return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
77    } else if(WheelPos < 170) {
78     WheelPos -= 85;
79     return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
80    } else {
81     WheelPos -= 170;
82     return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
83    }
84  }