当前位置:首页 > 科学研究 > 电子编程 > 正文内容

Arduino Project 008 - RGB LED Mood Lamp

RonWang5个月前 (07-09)电子编程85

In the last project, you learned how to adjust the brightness of an LED using the PWM capabilities of the Atmega chip. You’ll now take advantage of this capability by using a red, green, and blue LED and mixing these colors to create any color you wish. From that, you’ll create a mood lamp similar to those seen in stores nowadays.

项目8 RGB Mood Lamp 

08 RGB Mood Lamp Circuit

08 RGB Mood Lamp Schematic

/* Coding Ron Wang
   July 9th 2024
   Autaba support for coding hardware
 */
// Project 8 - Mood Lamp
float RGB1[3];
float RGB2[3];
float INC[3];
int red, green, blue;
int RedPin = 10;
int GreenPin = 9;
int BluePin = 8;
void setup()
{
 randomSeed(analogRead(0));
 RGB1[0] = 0;
 RGB1[1] = 0;
 RGB1[2] = 0;
 RGB2[0] = random(256);
 RGB2[1] = random(256);
 RGB2[2] = random(256);
}
void loop()
{
 randomSeed(analogRead(0));
 for (int x=0; x<3; x++) {
 INC[x] = (RGB1[x] - RGB2[x]) / 256; }
 for (int x=0; x<256; x++) {
 red = int(RGB1[0]);
 green = int(RGB1[1]);
 blue = int(RGB1[2]);
 analogWrite (RedPin, red);
 analogWrite (GreenPin, green);
 analogWrite (BluePin, blue);
 delay(100);
 RGB1[0] -= INC[0];
 RGB1[1] -= INC[1];
 RGB1[2] -= INC[2];
 }
 for (int x=0; x<3; x++) {
 RGB2[x] = random(556)-300;
 RGB2[x] = constrain(RGB2[x], 0, 255);
 delay(1000);
 }
}

版权声明:本文为原创文章,版权归donstudio所有,欢迎分享本文,转载请保留出处!

本文链接:http://parentscn.com/?id=258

标签: Arduino

相关文章

Arduino Project 028A - Basic Stepper Control (Bipolar)

Arduino Project 028A - Basic Stepper Control (Bipolar)

In this very simple project, you will connect up a stepper motor and then get the Arduino to control...

Arduino Programming Basic - Serial Monitor

Arduino Programming Basic - Serial Monitor

Arduino 程序基础,介绍Arduino程序的基本组成,第一部分编写数个例程,讲解关于变量及变量名称,串口监视器,if循环,for循环,while循环等。第二部分介绍了函数,全局变量,局部变量和静...

Arduino Project 050 - IR Remote Control Light

Arduino Project 050 - IR Remote Control Light

Project 50 IR Remote Control Light/* Project 50 IR Remote Control Ligh...

Arduino Project 040 - Ultrasonic Distance Alarm

Arduino Project 040 - Ultrasonic Distance Alarm

The sensor consists of two primary components: a transmitter and a receiver . The transmitter is res...

Arduino Project 030A - Dual Motor Driver L298N

Arduino Project 030A - Dual Motor Driver L298N

L298N Dual Motor Driver Project Description  The L298N Motor Driver is a control...

Arduino Project 002 - LED SOS Morse Code Singal

Arduino Project 002 - LED SOS Morse Code Singal

Arduino 电子编程--灯项目及控制,主要使用Arduino编程控制LED灯,实现基本控制Project 2 LED闪烁S.O.S信号。项目2 Project 2 S.O.S...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。