Arduino Quick Start
M5StampPico
.Connect the device to the computer via a USB cable and a USB-TTL adapter board, and the corresponding device's port can be selected in Arduino IDE.
Enter the following code in the Arduino IDE workspace, and click the upload button. The program will be automatically compiled and uploaded.
#include <Arduino.h>
#include <FastLED.h>
#define PIN_BUTTON 39
#define PIN_LED 27
#define NUM_LEDS 1
CRGB leds[NUM_LEDS];
uint8_t led_ih = 0;
uint8_t led_status = 0;
String led_status_string[] = {"Rainbow", "Red", "Green", "Blue"};
void setup() {
Serial.begin(115200);
Serial.println("Stamp-Pico demo!");
pinMode(PIN_BUTTON, INPUT);
FastLED.addLeds<WS2812, PIN_LED, GRB>(leds, NUM_LEDS);
}
void loop() {
switch (led_status) {
case 0:
leds[0] = CHSV(led_ih, 255, 255);
break;
case 1:
leds[0] = CRGB::Red;
break;
case 2:
leds[0] = CRGB::Green;
break;
case 3:
leds[0] = CRGB::Blue;
break;
default:
break;
}
FastLED.show();
led_ih++;
delay(15);
if (!digitalRead(PIN_BUTTON)) {
delay(5);
if (!digitalRead(PIN_BUTTON)) {
led_status++;
if (led_status > 3) led_status = 0;
while (!digitalRead(PIN_BUTTON))
;
Serial.print("LED status updated: ");
Serial.println(led_status_string[led_status]);
}
}
}
After uploading the code, the RGB LED on the Stamp-Pico device will light up automatically. Pressing the button allows you to cycle through the display colors of the LED. At the same time, the device will output the current light status information (such as color values or modes) through the serial port, facilitating debugging and interactive feedback.