Skip to content

Commit 50f62d2

Browse files
authored
Merge pull request #1572 from kattni/st-arduino
Arduino demo.
2 parents 4425723 + d5a89b8 commit 50f62d2

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

Slider_Trinkey/Arduino_Slider_Trinkey_Demo/.slidetrinkey_m0.test.only

Whitespace-only changes.
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include <Adafruit_NeoPixel.h>
2+
#include "Adafruit_FreeTouch.h"
3+
4+
// Create the neopixel strip with the built in definitions NUM_NEOPIXEL and PIN_NEOPIXEL
5+
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_NEOPIXEL, PIN_NEOPIXEL, NEO_GRB + NEO_KHZ800);
6+
// Create the touch pad
7+
Adafruit_FreeTouch qt = Adafruit_FreeTouch(PIN_TOUCH, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
8+
9+
int16_t neo_brightness = 255; // initialize with highest brightness
10+
11+
void setup() {
12+
Serial.begin(9600);
13+
//while (!Serial);
14+
15+
strip.begin();
16+
strip.setBrightness(neo_brightness);
17+
strip.show(); // Initialize all pixels to 'off'
18+
19+
analogReadResolution(12); // set highest resolution
20+
21+
if (! qt.begin())
22+
Serial.println("Failed to begin qt");
23+
}
24+
25+
void loop() {
26+
uint16_t touch = qt.measure();
27+
Serial.print("Touch: "); Serial.println(touch);
28+
29+
uint16_t potval = analogRead(PIN_POTENTIOMETER);
30+
Serial.print("Slider: ");
31+
Serial.println((float)potval / 4095);
32+
33+
uint8_t wheelval = map(potval, 0, 4095, 0, 255);
34+
//Serial.print("Wheel: ");
35+
//Serial.println(wheelval);
36+
37+
// If the pad is touched, turn off neopix!
38+
if (touch > 500) {
39+
Serial.println("Touched!");
40+
strip.setBrightness(0);
41+
} else {
42+
strip.setBrightness(255);
43+
}
44+
45+
for(int i=0; i< strip.numPixels(); i++) {
46+
strip.setPixelColor(i, Wheel((wheelval+85) % 255));
47+
}
48+
49+
strip.show();
50+
delay(10);
51+
}
52+
53+
// Input a value 0 to 255 to get a color value.
54+
// The colours are a transition r - g - b - back to r.
55+
uint32_t Wheel(byte WheelPos) {
56+
if(WheelPos < 85) {
57+
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
58+
} else if(WheelPos < 170) {
59+
WheelPos -= 85;
60+
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
61+
} else {
62+
WheelPos -= 170;
63+
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
64+
}
65+
}

0 commit comments

Comments
 (0)