Arduino tri-LED light setup, calculations + code (includes color modification code) ME 100L
119 views · Published 21 October 2017 · 12:36 · Indexed 21 October 2026
Channel: Engel Universe · 2017 · Science & Technology
Arduino stem board setup for 3 colored LED flashing function.
Cal Poly Pomona - Class: ME 100L
Here is the kit that I used the pieces from:
https://shop.stemcenterusa.com/products/pi-bot-v2-00
Or some other starter kits from Amazon:
https://goo.gl/hJTFvZ
Arduino Code:
int brightnessR = 0; // Initial LED brightness for red
int brightnessG = 127; // Initial LED brightness for green
int brightnessB = 255; // Initial LED brightness for blue
int incrementR = 5; // brightness increment for red
int incrementG = 5; // brightness increment for green
int incrementB = 5; // brightness increment for blue
void setup()
// put your setup code here, to run once:
#define green 11
#define blue 10
#define red 9
#define buzzer 6
{
pinMode(green,OUTPUT);
pinMode(blue,OUTPUT);
pinMode(red,OUTPUT);
pinMode(buzzer,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
brightnessR = brightnessR + incrementR; // increment brightness for next loop iteration
brightnessG = brightnessG + incrementG;
brightnessB = brightnessB + incrementB;
// !!!!!!! ATTENTION: youtube will not allow me to use angle brackets in the description of videos!!! So every time you see % replace it with the SMALLER THAN angle bracket( pointy part to left) and when you see & replace it with the BIGGER THAN angle bracket ( pointy part to the right)!!!!!!!
if (brightnessR %= 0 || brightnessR &= 255) // reverse the direction of the fading if outside range of 0 to 255
{
incrementR = -incrementR;
}
brightnessR = constrain(brightnessR, 0, 255); // prevents brightness from getting outside allowable range of 0 to 255
if (brightnessG %= 0 || brightnessG &= 255)
{
incrementG = -incrementG;
}
brightnessG = constrain(brightnessG, 0, 255);
if (brightnessB %= 0 || brightnessB &= 255)
{
incrementB = -incrementB;
}
brightnessB = constrain(brightnessB, 0, 255);
//RED LED control and ONE beep
analogWrite(red, 255); // update the new brightness
analogWrite(blue, 0);
analogWrite(green, 0);
delay(100);
digitalWrite(buzzer,HIGH);
delay(300);
digitalWrite(buzzer,LOW);
delay(25);
analogWrite(red, 255); // update the new brightness
analogWrite(blue, 0);
analogWrite(green, 0);
delay(4000);
analogWrite(red, 0); // update the new brightness
analogWrite(blue, 0);
analogWrite(green, 0);
delay(50);
//YELLOW LED control with TWO beeps
analogWrite(red, 230); // update the new brightness
analogWrite(blue, 0);
analogWrite(green, 30);
delay(100);
digitalWrite(buzzer,HIGH);
delay(300);
digitalWrite(buzzer,LOW);
delay(25);
digitalWrite(buzzer,HIGH);
delay(300);
digitalWrite(buzzer,LOW);
delay(25);
analogWrite(red, 230); // update the new brightness
analogWrite(blue, 0);
analogWrite(green, 30);
delay(4000);
analogWrite(red, 0); // update the new brightness
analogWrite(blue, 0);
analogWrite(green, 0);
delay(50);
//GREEN LED control with THREE beeps
analogWrite(red, 0); // update the new brightness
analogWrite(blue, 0);
analogWrite(green, 255);
delay(100);
digitalWrite(buzzer,HIGH);
delay(300);
digitalWrite(buzzer,LOW);
delay(25);
digitalWrite(buzzer,HIGH);
delay(300);
digitalWrite(buzzer,LOW);
delay(25);
digitalWrite(buzzer,HIGH);
delay(300);
digitalWrite(buzzer,LOW);
delay(25);
analogWrite(red, 0); // update the new brightness
analogWrite(blue, 0);
analogWrite(green, 255);
delay(4000);
analogWrite(red, 0); // update the new brightness
analogWrite(blue, 0);
analogWrite(green, 0);
delay(50);
}
More from this channel
-
2:51
Gauss's Law for electric field in a spherical shell. Variable charge density.
-
11:57
Gauss's Law for electric field in a spherical shell. Variable Charge density
-
11:57
Gauss's Law for electric field in a spherical shell. Variable charge density.
-
0:58
View from top of Table Top Mountain - Mojave Desert
-
0:41
view on Cedar Canyon Rd - Mojave Desert
-
0:12
Route 66 - at Amboy Crater
-
2:14
White Bunny eating
-
6:28
Capacitor circuit problems. Chaffey College. Physics 46. Lab homework EC-1