Created
September 10, 2026 16:48
-
-
Save andrewflash/6a67dfbce3ead1360a9c618b62b8d2c6 to your computer and use it in GitHub Desktop.
Exilir AIoT Bootcamp Batch 1 - Chapter 2 - Blinking LED
This file contains hidden or 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
| /* | |
| * WS2812B Random RGB Color — ESP32-C5 | |
| * Data pin : GPIO27 (IO27) | |
| * Library : Adafruit_NeoPixel (Library Manager -> "Adafruit NeoPixel") | |
| * Board : ESP32C5 Dev Module (Arduino-ESP32 core 3.x ke atas) | |
| * | |
| * Setiap interval, tiap LED diberi warna acak. | |
| * Ubah MODE_ALL_SAME menjadi true kalau ingin seluruh strip satu warna acak yang sama. | |
| */ | |
| #include <Adafruit_NeoPixel.h> | |
| #define LED_PIN 27 // IO27 | |
| #define LED_COUNT 8 // jumlah LED pada strip, sesuaikan | |
| #define BRIGHTNESS 60 // 0-255, jangan terlalu tinggi kalau daya dari USB | |
| #define INTERVAL_MS 500 // jeda ganti warna (ms) | |
| #define MODE_ALL_SAME false // true = semua LED warna acak yang sama | |
| Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); | |
| uint32_t randomColor() { | |
| // Warna acak "hidup" (saturasi penuh) via roda HSV, | |
| // supaya tidak sering keluar warna kusam/keabu-abuan. | |
| uint16_t hue = random(0, 65536); | |
| return strip.gamma32(strip.ColorHSV(hue, 255, 255)); | |
| } | |
| void setup() { | |
| Serial.begin(115200); | |
| // Seed acak dari noise ADC + hardware RNG ESP32 | |
| randomSeed(esp_random()); | |
| strip.begin(); | |
| strip.setBrightness(BRIGHTNESS); | |
| strip.clear(); | |
| strip.show(); | |
| Serial.println("WS2812B random color siap di GPIO27"); | |
| } | |
| void loop() { | |
| if (MODE_ALL_SAME) { | |
| uint32_t c = randomColor(); | |
| for (int i = 0; i < LED_COUNT; i++) { | |
| strip.setPixelColor(i, c); | |
| } | |
| } else { | |
| for (int i = 0; i < LED_COUNT; i++) { | |
| strip.setPixelColor(i, randomColor()); | |
| } | |
| } | |
| strip.show(); | |
| delay(INTERVAL_MS); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment