【笔记】Arduino控制RGB-LED灯模块

前言

Arduino UNO R4控制RGB-LED灯模块

接线图

flowchart LR
  subgraph UNO ["Arduino UNO R4"]
    Pin_11(("~11"))
    Pin_10(("~10"))
    Pin_9(("~9"))
    Pin_GND(("GND"))
  end

  subgraph Module ["RGB-LED灯模块"]
    A(("R"))
    B(("G"))
    C(("B"))
    D(("GND"))
  end

  Pin_11 --- A
  Pin_10 --- B
  Pin_9 --- C
  Pin_GND --- D

源代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
const int R_PIN = 11;
const int G_PIN = 10;
const int B_PIN = 9;

void setup()
{
pinMode(R_PIN, OUTPUT);
pinMode(G_PIN, OUTPUT);
pinMode(B_PIN, OUTPUT);
}

void loop()
{
color(255, 255, 255);
}

void color(unsigned char red, unsigned char green, unsigned char blue)
{
analogWrite(R_PIN, red);
analogWrite(G_PIN, green);
analogWrite(B_PIN, blue);
}

完成

参考文献

哔哩哔哩——创乐博智能科技