Last active
November 15, 2022 05:55
-
-
Save cosismo/5c7ef47be6f8b82ce6f2192ec6813e6a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*WS2812 RGB blink buit-in led | |
Tested with esp32-arduino v 2.0.3 & v 2.0.5 library on generic esp32s3 purble board | |
https://raw.githubusercontent.com/cosismo/esp32-s3/gh-pages/Purple-S3-pinout.png | |
Relevant Arduino IDE config: | |
Flash Mode: DIO 80MHz | |
Flash Size: 16MB (128Mb) | |
PSRAM: QSPI PSRAM | |
Partition Scheme: 16MB Flash (3MB APP /9.9MB FATFS) | |
*/ | |
#include <Adafruit_NeoPixel.h> //Tested with Adafruit_NeoPixel v 1.10.6 | |
// Which pin on the Arduino is connected to the NeoPixels? | |
#define PIN 48 // ESP32S3 Generic AI-S3 (Purple) | |
// How many NeoPixels are attached to the Arduino? | |
#define NUMPIXELS 1 | |
// Setting up the NeoPixel library | |
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); | |
#define DELAYVAL 500 // Time (in milliseconds) to pause between pixels | |
static uint8_t brightness = 128; | |
static uint8_t r = 0; | |
static uint8_t g = 0; | |
static uint8_t b = 0; | |
void setup() { | |
Serial.begin(115200); | |
pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) | |
} | |
void loop() { | |
pixels.clear(); // Set all pixel colors to 'off' | |
for (uint8_t i = 1; i < 8; i++) { | |
/* Get the rgb bits shifting the counter variable | |
to the right and then masking with AND 0x1 */ | |
bool r = ( (i >> 2) & 1 ) * brightness; | |
bool g = ( (i >> 1) & 1 ) * brightness; | |
bool b = ( (i >> 0) & 1 ) * brightness; //shift 0, I know. Aesthetics and symmetry ;) | |
Serial.printf("i= %d | rgb bits = r:%d, g:%d, b:%d,\n", i, r, g, b); | |
pixels.setPixelColor(0, pixels.Color(r, g, b)); | |
pixels.show(); // Send the updated pixel colors to the hardware. | |
delay(DELAYVAL); // Pause before next pass through loop | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍