Skip to content

Commit 5b0c44e

Browse files
committed
Re-uploading corrected code
Trying this again.. uploading the correct code for the Color Touch Necklace guide.
1 parent ac54694 commit 5b0c44e

1 file changed

Lines changed: 139 additions & 0 deletions

File tree

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
// Code by Erin St. Blaine for Adafruit Industries
2+
// Color Touch Pendant Tutorial: https://learn.adafruit.com/color-touch-pendant-necklace/introduction
3+
// Two neopixel rings connected on pin 1 will cycle through gradient colors when the pendant is touched. For Gemma M0.
4+
5+
#include "Adafruit_FreeTouch.h"
6+
#include "FastLED.h"
7+
8+
#define CAPTOUCH_PIN 0 //capacitive touch pin
9+
#define NEOPIXEL_PIN 1 //neopixel ring pin
10+
#define NUM_LEDS 28 //how many pixels total
11+
12+
#define LED_TYPE WS2812
13+
#define COLOR_ORDER GRB
14+
CRGB leds[NUM_LEDS]; //LED array
15+
16+
// These variables will affect the way the gradient animation looks. Feel free to mess with them.
17+
int SPEEDO = 10;
18+
int STEPS = 50;
19+
int HUE = 0;
20+
int SATURATION = 255;
21+
int COLORCHANGE = 50;
22+
int BRIGHTNESS = 110;
23+
24+
// Calibrating your capacitive touch sensitivity: Change this variable to something between your capacitive touch serial readouts for on and off
25+
int touch = 650;
26+
27+
long oldState = 0;
28+
29+
// set up capacitive touch button using the FreeTouch library
30+
Adafruit_FreeTouch qt_1 = Adafruit_FreeTouch(CAPTOUCH_PIN, OVERSAMPLE_4, RESISTOR_50K, FREQ_MODE_NONE);
31+
32+
33+
TBlendType currentBlending;
34+
CRGBPalette16 currentPalette;
35+
36+
37+
void setup() {
38+
Serial.begin(115200);
39+
40+
if (! qt_1.begin())
41+
Serial.println("Failed to begin qt on pin A1");
42+
FastLED.addLeds<WS2812, NEOPIXEL_PIN, COLOR_ORDER>(leds, NUM_LEDS); // Set up neopixels with FastLED
43+
FastLED.setBrightness(BRIGHTNESS); // set global brightness
44+
FastLED.setMaxPowerInVoltsAndMilliamps(3,350); //Constrain FastLED's power usage
45+
}
46+
47+
void loop() {
48+
49+
Serial.print(qt_1.measure());
50+
Serial.write(' ');
51+
checkpress(); //check to see if the button's been pressed
52+
//delay(20);
53+
}
54+
55+
void checkpress() {
56+
57+
// Get current button state.
58+
59+
long newState = qt_1.measure();
60+
Serial.println(qt_1.measure());
61+
if (newState > touch && oldState < touch) {
62+
// Short delay to debounce button.
63+
delay(500);
64+
// Check if button is still low after debounce.
65+
long newState = qt_1.measure(); }
66+
67+
68+
if (newState > touch ) {
69+
HUE=HUE+COLORCHANGE; // change the hue by a specified amount each time the cap touch pad is activated
70+
if (HUE > 255){
71+
HUE=0;}
72+
Gradient();
73+
}
74+
// if (HUE==250) {
75+
// dark();
76+
// }
77+
else {
78+
Gradient();
79+
80+
}
81+
82+
83+
84+
// Set the last button state to the old state.
85+
oldState = newState;
86+
87+
}
88+
89+
90+
91+
// GRADIENT --------------------------------------------------------------
92+
void Gradient()
93+
{
94+
SetupGradientPalette();
95+
96+
static uint8_t startIndex = 0;
97+
startIndex = startIndex - 1; // motion speed
98+
99+
FillLEDsFromPaletteColors( startIndex);
100+
FastLED.show();
101+
FastLED.delay(SPEEDO);
102+
}
103+
104+
// adjust hue, saturation and brightness values here to make a pleasing gradient
105+
106+
void SetupGradientPalette()
107+
{
108+
CRGB light = CHSV( HUE + 25, SATURATION - 20, BRIGHTNESS);
109+
CRGB lightmed = CHSV (HUE + 15, SATURATION - 10, BRIGHTNESS-50);
110+
CRGB medium = CHSV ( HUE + 10, SATURATION - 15, BRIGHTNESS);
111+
CRGB dark = CHSV( HUE, SATURATION, BRIGHTNESS);
112+
CRGB black = CHSV (HUE, SATURATION, 0);
113+
114+
currentPalette = CRGBPalette16(
115+
black, light, light, light,
116+
lightmed, lightmed, lightmed, medium,
117+
medium, medium, medium, dark,
118+
dark, dark, dark, black );
119+
}
120+
121+
void FillLEDsFromPaletteColors( uint8_t colorIndex)
122+
{
123+
uint8_t brightness = BRIGHTNESS;
124+
125+
for( int i = 0; i < NUM_LEDS; i++) {
126+
leds[i] = ColorFromPalette( currentPalette, colorIndex, brightness, currentBlending);
127+
colorIndex += STEPS;
128+
}
129+
}
130+
131+
void dark()
132+
{
133+
for(int i = 0; i < NUM_LEDS; i++) {
134+
leds[i] = CRGB::Black;
135+
FastLED.show();
136+
delay(20);
137+
}
138+
}
139+

0 commit comments

Comments
 (0)