pdf-icon

Arduino 上手教程

2. 设备开发 & 案例程序

NanoC6 Arduino 示例程序编译与烧录

1.准备工作

2.端口选择

将设备通过USB线连接至电脑,在Arduino IDE中可选中对应设备的端口。

3.程序编译&烧录

在Arduino IDE 工作区输入下方代码, 点击上传按钮,将自动进行程序编译与烧录。

说明:
1.本案例基于Adafruit NeoPixel库实现, 使用前请通过库管理安装Adafruit NeoPixel依赖库。
2.M5NanoC6 LED 为 RGB 灯珠,需要使能灯珠,即需要高电平控制下方代码中的 ENABLE_PIN
cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
#include <Adafruit_NeoPixel.h>

#define LED_PIN    20
#define ENABLE_PIN 19
#define NUM_LEDS   1

Adafruit_NeoPixel strip(NUM_LEDS, LED_PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  pinMode(ENABLE_PIN, OUTPUT);
  digitalWrite(ENABLE_PIN, HIGH); 
  strip.begin();
  strip.show(); 
}

void loop() {
    //RED
    strip.setPixelColor(0, strip.Color(255, 0, 0)); 
    strip.show();
    delay(100);
  
    //GREEN
    strip.setPixelColor(0, strip.Color(0, 255, 0)); 
    strip.show();
    delay(100);
  
    //BLUE
    strip.setPixelColor(0, strip.Color(0, 0, 255)); 
    strip.show();
    delay(100);
}

上传代码后即可看到 M5NanoC6 设备上的RGB LED灯循环亮起红绿蓝三色。

On This Page