CODE | RGB LED Mood Lamp - Arduino Project 008

RonWang3 years ago (2023-07-07)电子编程 COD4

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);
 }
}

           

Share with Friends:

Related Articles

CODE | SD Card Information Basic - Arduino Project 042

CODE | SD Card Information Basic - Arduino Project 042

Arduino Programming Basic -- Reading and Writing to an SD CardSD cards have non-volatile flash memor…

CODE | LED SOS Morse Code Singal - Arduino Project 002

CODE | LED SOS Morse Code Singal - Arduino Project 002

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

CODE | Servo Control - Arduino Project 025

CODE | Servo Control - Arduino Project 025

You will need to obtain a standard RC servo; any of the small or mid-sized servos will do. Larger se…

Series and Parallel resistors

Series and Parallel resistors

Two-terminal components and electrical networks can be connected in series or parallel. The resultin…

Electric Maker Beginner Tools Kit

Electric Maker Beginner Tools Kit

This assortment of tools has everything you need to get started tinkering with Sparkfun products and…

Resistor-Electrical Components

Resistor-Electrical Components

A resistor is a passive two-terminal electrical component that implements electrical resistance as a…

Post a Comment

Anonymous

Feel free to share your thoughts and opinions here.