I am trying to fudge together a code for the Heltec ESP32 Wifi Kit to be able to change NeoPixel patterns with a button push but I’m having a very difficult time understanding how to get the button push to change between “functions”. Any help is greatly appreciated.
#include <Arduino.h>
#include <U8g2lib.h>
#define FASTLED_INTERNAL
#include <FastLED.h>
#include <OneButton.h>
#define OLED_CLOCK 15
#define OLED_DATA 4
#define OLED_RESET 16
#define NUM_LEDS 60
#define LED_PIN 5
#define BUTTON_PIN 14
OneButton button1(14, true);
CRGB g_LEDs[NUM_LEDS] = {0};
U8G2_SSD1306_128X64_NONAME_F_HW_I2C g_OLED(U8G2_R2, OLED_RESET, OLED_CLOCK, OLED_DATA);
int g_lineHeight = 0;
double FramesPerSecond(double seconds)
{
static double framesPerSecond;
framesPerSecond = (framesPerSecond * .9) + (1.0 / seconds * .1);
return framesPerSecond;
}
void setup()
{
pinMode(LED_PIN, OUTPUT);
Serial.begin(115200);
while (!Serial) { }
Serial.println("ESP32 Startup");
g_OLED.begin();
g_OLED.clear();
g_OLED.setFont(u8g2_font_profont15_tf);
g_lineHeight = g_OLED.getFontAscent() - g_OLED.getFontDescent();
FastLED.addLeds<WS2812B, LED_PIN, GRB>(g_LEDs, NUM_LEDS);
FastLED.setBrightness(255);
}
void loop()
{
button1.tick();
delay(10);
if (button1 =! HIGH);
switch(button1);
(
case 0:
void DrawComet();
{
g_OLED.clearBuffer();
g_OLED.setCursor(0, g_lineHeight);
g_OLED.printf("COMET");
g_OLED.sendBuffer();
const byte fadeAmt = 128;
const int cometSize = 5;
const int deltaHue = 4;
static byte hue = HUE_RED;
static int iDirection = 1;
static int iPos = 0;
hue += deltaHue;
iPos += iDirection;
if (iPos == (NUM_LEDS - cometSize) || iPos == 0)
iDirection *= -1;
for (int i = 0; i < cometSize; i++)
g_LEDs[iPos + i].setHue(hue);
for (int j = 0; j < NUM_LEDS; j++)
if (random(10) > 5)
g_LEDs[j] = g_LEDs[j].fadeToBlackBy(fadeAmt);
delay(0.5);
}
break;
case 1:
void rainbow(); {
uint8_t initialHue = 0;
const uint8_t deltaHue = 16;
const uint8_t hueDensity = 4;
for (;;)
{
double dStart = millis() / 1000.0;
// Handle OLED drawing
g_OLED.clearBuffer();
g_OLED.setCursor(0, g_lineHeight);
g_OLED.printf("RAINBOW");
g_OLED.sendBuffer();
fill_rainbow(g_LEDs, NUM_LEDS, initialHue += hueDensity, deltaHue);
}
break;
}
)
}
FastLED.show();
double dEnd = millis() / 1000.0;