Skip to content

Instantly share code, notes, and snippets.

@IdrisCytron
Created June 24, 2020 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IdrisCytron/e1e6a5f02ba83da60c8cd46c4e4e260f to your computer and use it in GitHub Desktop.
Save IdrisCytron/e1e6a5f02ba83da60c8cd46c4e4e260f to your computer and use it in GitHub Desktop.
Controlling built-in WS2812B RGB LED on Cucumber board.
/*
Tutorial: Program ESP32-S2 Using Arduino IDE (Unofficial)
Board: ESP32S2 (Cucumber from Gravitech)
External libraries:
- Adafruit NeoPixel V1.5.0 (Manager)
*/
#include <Adafruit_NeoPixel.h>
#define PIN 18
#define NUMPIXELS 1
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
enum {NONE, RED, GREEN, BLUE};
int ledColor = NONE;
void setup()
{
pixels.begin();
}
void loop()
{
switch (ledColor) {
case NONE:
pixels.setPixelColor(0, pixels.Color(0, 0, 0));
pixels.show();
break;
case RED:
pixels.setPixelColor(0, pixels.Color(20, 0, 0));
pixels.show();
break;
case GREEN:
pixels.setPixelColor(0, pixels.Color(0, 20, 0));
pixels.show();
break;
case BLUE:
pixels.setPixelColor(0, pixels.Color(0, 0, 20));
pixels.show();
break;
default:
break;
}
ledColor++;
if (ledColor == 4) {
ledColor = NONE;
}
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment