从0开始学习STM32 | day2

发布于 2023-03-28  167 次阅读


前言

今天到了一块STM32F103C8T6的开发板,打算从这个开发板开始入门学习单片机编程。使用的环境是Arduino IDE。

商家好心地给了一个原理图,部分见下:

基于Arduino IDE的STM32开发

一个简单的RBG LED的示例程序如下:

/*
  RGB_LED_TLC59731

  This example code is in the public domain.

  Blink one RGB LED with different default colors:
    RGB_LED_TLC59731::OFF
    RGB_LED_TLC59731::RED
    RGB_LED_TLC59731::GREEN
    RGB_LED_TLC59731::BLUE
    RGB_LED_TLC59731::MAGENTA
    RGB_LED_TLC59731::CYAN
    RGB_LED_TLC59731::YELLOW
    RGB_LED_TLC59731::WHITE
*/

#include <RGB_LED_TLC59731.h>

static uint8_t step = 0;
static uint8_t* sequence[] = { RGB_LED_TLC59731::RED,
                              RGB_LED_TLC59731::GREEN,
                              RGB_LED_TLC59731::BLUE,
                              RGB_LED_TLC59731::MAGENTA,
                              RGB_LED_TLC59731::CYAN,
                              RGB_LED_TLC59731::YELLOW,
                              RGB_LED_TLC59731::WHITE
                            };
/**
    STM32WB5MM-DK have an RGB LED connected to TLC59731
    It requires to enable it thanks LED_SELECT pin
    and to have JP5 on and JP4 off
*/
#if defined(RGB_LED) && defined(LED_SELECT)
RGB_LED_TLC59731 myLED(RGB_LED, LED_SELECT);
#else
RGB_LED_TLC59731 myLED;
#endif

void setup() {
  /* Change Brightness */
  myLED.setBrightness(0x10);
}

void loop() {
  /* Blink */
  myLED.on(sequence[step]);
  delay(500);
  myLED.off();
  delay(500);
  step = (step == 6) ? 0 : step + 1;
}

该代码来源于Arduino IDE的示例代码,实现的是LED的RBG闪烁功能。


Love board, love anime, love DetLFY.