The Anxinke BW16-Kit combined with the color temperature control function can create a colorful light environment to meet the needs of smart home lighting or other lighting applications. To achieve color temperature control, use LED lights with color temperature adjustment function and control these LED lights through the GPIO pins of the BW16-Kit.
Make sure the LED light supports color temperature adjustment and has an interface compatible with the BW16-Kit. Then, connect the LED light to the GPIO pins of the BW16-Kit (onboard). According to the requirements of the LED light, you need to add appropriate drive circuits and resistors.
In terms of software, you can use Arduino IDE or other development environments that support BW16-Kit to write code. By writing code, you can control the output of GPIO pins to adjust the color temperature of the LED light. The specific code implementation depends on the LED light and control protocol you use.
To be practical, send a number from 1 to 100 through the serial port to change the color temperature of the illuminated LED. Make sure your LED lamp or LED strip supports color temperature adjustment and has been correctly connected to the GPIO pin of the Essence BW16-Kit. Next, you need to write code to monitor the data received by the serial port and adjust the color temperature of the LED lamp according to the received digital value.
Actual output:
Code:
void setup() {
pinMode(PA12, OUTPUT);
// pinMode(PA14, OUTPUT);
pinMode(PA13, OUTPUT);
Serial.begin(115200); // 初始化串口
}
int calculateColorValue(int colorTemp, int minVal, int maxVal) {
// 根据色温数值和最小最大值计算颜色亮度
int val = map(colorTemp, 0, 100, minVal, maxVal);
return val;
}
void loop() {
// 读取串口数据
if (Serial.available() > 0) {
int colorTemp = Serial.parseInt(); // 读取串口发送的色温数值
Serial.print("the color tmp is set as ");
Serial.print(colorTemp);
Serial.print("/r/n");
// 根据色温数值调整颜色亮度
// analogWrite(PA14, calculateColorValue(colorTemp, 0, 255));//这个引脚打开之后就出现问题,不开一切正常
analogWrite(PA12, calculateColorValue(colorTemp, 0, 255));
analogWrite(PA13, calculateColorValue(colorTemp, 0, 255));
}
}
Output effect:
ef611b1612de78c0e4a2c41b268a8214
|