I am new to Blynk and am writing a sketch to control neopixel strips with a menu system. I followed the code example but my sketch kicks out after each selection instead of staying in a loop. I know I am missing something simple, I just cant see it. The code isn’t long as most of the menu options have not been filled out yet. Thanks in advance for any help. - Jeff
/**************************************************************
* Blynk is a platform with iOS and Android apps to control
* Arduino, Raspberry Pi and the likes over the Internet.
* You can easily build graphic interfaces for all your
* projects by simply dragging and dropping widgets.
*
* Downloads, docs, tutorials: http://www.blynk.cc
* Blynk community: http://community.blynk.cc
* Social networks: http://www.fb.com/blynkapp
* http://twitter.com/blynk_app
*
* Blynk library is licensed under MIT license
*
*
**************************************************************
*
* Pylon Controller for ESP 8266
*
*
**************************************************************/
#include <Adafruit_NeoPixel.h>
#include <SPI.h>
#include <BlynkSimpleEsp8266.h>
#include <ESP8266WiFi.h>
#include <SimpleTimer.h>
#include <ESP8266WebServer.h>
#define PIN 15 // GPIO pin
#define NUMPIXELS 60 // Number of pixels in strip
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
SimpleTimer timer;
SimpleTimer quickTimer;
char auth[] = "TOKEN"; // Auth Token from the Blynk App.
// Setup
void setup() {
Serial.begin(9600);
Blynk.begin(auth, "SSID", "PWORD");
strip.begin();
}
// Menu Section
BLYNK_WRITE(V1) {
switch (param.asInt())
{
case 1: { // Solid Red
colorWipe(strip.Color(255, 0, 0), 0);
break;
}
case 2: { // Solid Green
colorWipe(strip.Color(0, 255, 0), 0);
break;
}
case 3: { // Solid Blue
colorWipe(strip.Color(0, 0, 255), 0);
break;
}
case 4: { // Solid Yellow
colorWipe(strip.Color(255, 255, 0), 0);
break;
}
case 5: { // Solid Magents
colorWipe(strip.Color(255, 0, 255), 0);
break;
}
case 6: { // Solid Cyan
colorWipe(strip.Color(0, 255, 255), 0);
break;
}
case 7: { // Flashing Red
Serial.println("Item 7 selected");
break;
}
case 8: { // Flashing Green
Serial.println("Item 8 selected");
break;
}
case 9: { // Flashing Blue
Serial.println("Item 9 selected");
break;
}
case 10: { // Flashing Yellow
Serial.println("Item 10 selected");
break;
}
case 11: { // Flashing Magenta
Serial.println("Item 11 selected");
break;
}
case 12: { // Flashing Cyan
Serial.println("Item 12 selected");
break;
}
case 13: { // Stripe Red
colorWipe(strip.Color(255, 0, 0), 50);
break;
}
case 14: { // Stripe Green
colorWipe(strip.Color(0, 255, 0), 50);
break;
}
case 15: { // Stripe Blue
colorWipe(strip.Color(0, 0, 255), 50);
break;
}
case 16: { // Stripe Yellow
colorWipe(strip.Color(255, 255, 0), 50);
break;
}
case 17: { // Stripe Magenta
colorWipe(strip.Color(255, 0, 255), 50);
break;
}
case 18: { // Stripe Cyan
colorWipe(strip.Color(0, 255, 255), 50);
break;
}
case 19: { // Rainbow
rainbow(20);
break;
}
case 20: { // Moving Rainbow
rainbowCycle(20);
break;
}
case 21: { // Fire
Serial.println("Item 21 selected");
break;
}
case 22: { // Snow
Serial.println("Item 22 selected");
break;
}
case 23: { // Checker
Serial.println("Item 23 selected");
break;
}
case 24: { // unused 1
Serial.println("Item 24 selected");
break;
}
case 25: { // unused 25
colorWipe(strip.Color(255, 0, 0), 50);
break;
}
default: {
Serial.println("Unknown item selected");
}
}
}
// Main Loop
void loop() {
timer.run();
quickTimer.run();
Blynk.run();
}
// Color Wheel Subroutine
// Input a value 0 to 255 to get a color value. The colors are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
// ColorWipe Subroutine: Fill the dots bottom to top with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=strip.numPixels(); i>=0; i--) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
// Rainbow Subroutine: Create Rainbow from top to bottom
void rainbow(uint8_t) {
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
}
}
// Moving Rainbow Subroutine: Cycle Rainbow from top to bottom
void rainbowCycle(uint8_t) {
uint16_t i, j;
for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
}
}