-
Notifications
You must be signed in to change notification settings - Fork 46
/
Blynk_Teensy32_USB_test.ino
161 lines (132 loc) · 4.25 KB
/
Blynk_Teensy32_USB_test.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//***************************************************************
// Blynk test with Teensy 3.2 and USB connection.
//
// Four widgets were used to send data from the Blynk app:
// - Button (turns display on/off)
// - Slider (controls brightness)
// - zeRGBa (RGB data sets pixel color)
// - Menu (selects a pattern)
//
// Looks like this on my phone:
// https://i.imgur.com/6x9AvOQ.png
//
// Marc Miller, Oct 2017
// update: Feb 2018 - added a simple Menu example
//***************************************************************
/*************************************************************
Download latest Blynk library here:
https://github.com/blynkkk/blynk-library/releases/latest
Blynk downloads, docs, tutorials, etc:
http://www.blynk.cc
Blynk USB HOWTO info:
http://tiny.cc/BlynkUSB
*************************************************************/
//---------------------------------------------------------------
#include "FastLED.h" //include FastLED library
#define NUM_LEDS 32 // Number of pixels in strip
CRGB leds[NUM_LEDS];
void solid();
void rainbow();
void juggle();
void sinelon();
typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = { solid, rainbow, juggle, sinelon };
uint8_t gHue = 0; // rotating "base color" used by many of the patterns
//---------------------------------------------------------------
#include <BlynkSimpleStream.h>
// Blynk App. Auth Token goes here:
char auth[] = "put_your_token_number_here_inside_the_quotes";
// define custom variables to hold incoming data from Blynk widgets
uint8_t sliderBrightness; //output: V1, slider
uint8_t zeRGBa[3]; //output: V2, zeRGBa data (set to "merge")
boolean buttonA; //output: V3, button (set as "switch")
uint8_t pattern; //output: V4, current pattern number
BLYNK_WRITE(V1) //slider value 0-255
{
sliderBrightness = param.asInt(); // assigning incoming value from pin V1 to a variable
}
BLYNK_WRITE(V2) //set as "merge" in zeRGBa widget
{
zeRGBa[0] = param[0].asInt(); //red
zeRGBa[1] = param[1].asInt(); //green
zeRGBa[2] = param[2].asInt(); //blue
}
BLYNK_WRITE(V3) //toggles pixel display On/Off, set as "switch"
{
buttonA = param.asInt(); //value is either 0 or 1
}
BLYNK_WRITE(V4) {
switch (param.asInt()) {
case 1: {
pattern = 1; //rainbow
break;
}
case 2: {
pattern = 2; //juggle
break;
}
case 3: {
pattern = 3; //sinelon (color selected by zeRGBa picker)
break;
}
case 4: {
pattern = 0; //solid (color selected by zeRGBa picker)
break;
}
default:
pattern = 0; //run if no pattern selected
}
}
//---------------------------------------------------------------
void setup()
{
// Blynk will work through Serial
// Do not read or write this serial manually in your sketch
Serial.begin(9600);
Blynk.begin(Serial, auth);
FastLED.addLeds<LPD8806,11,13,GRB>(leds, NUM_LEDS);
}
//---------------------------------------------------------------
void loop()
{
Blynk.run();
EVERY_N_MILLISECONDS(10) {
if (buttonA == 1) { //strip is ON.
gPatterns[pattern]();
} else { //strip is OFF
FastLED.clear(); //blank out all pixel data
}
FastLED.setBrightness(sliderBrightness);
FastLED.show();
}//end_EVERY_N
EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
}//end_main_loop
//---------------------------------------------------------------
// Patterns
//---------------------------------------------------------------
void rainbow()
{
// FastLED's built-in rainbow generator
fill_rainbow( leds, NUM_LEDS, gHue, NUM_LEDS/8);
}
void juggle() {
// four colored dots, weaving in and out of sync with each other
fadeToBlackBy( leds, NUM_LEDS, 20);
byte dothue = 0;
for( int i = 0; i < 4; i++) {
leds[beatsin16( i+5, 0, NUM_LEDS-1 )] |= CHSV(dothue, 200, 255);
dothue += 32;
}
}
void sinelon()
{
// a colored dot sweeping back and forth, with fading trails
fadeToBlackBy( leds, NUM_LEDS, 12);
int pos = beatsin16( 13, 0, NUM_LEDS-1 );
leds[pos] += CRGB(zeRGBa[0],zeRGBa[1],zeRGBa[2]);
}
void solid()
{
// fill entire strip with a solid color
fill_solid(leds, NUM_LEDS, CRGB(zeRGBa[0],zeRGBa[1],zeRGBa[2]) );
}