Working on the LED strip. Almost done with the LED strip control.

This commit is contained in:
Boyan 2024-03-15 01:19:50 +01:00
parent d1c31736a3
commit fbfcd89399
3 changed files with 37 additions and 18 deletions

1
.gitignore vendored Normal file

@ -0,0 +1 @@
.vscode/

@ -1 +1,5 @@
![WIRE](https://cdn.sparkfun.com/assets/learn_tutorials/7/9/0/Non_Addressable_LED_Strip_Simple_bb_Fritzing.png)
![WIRE](https://i0.wp.com/randomnerdtutorials.com/wp-content/uploads/2019/03/ESP32-LED-strip-schematic_f.png?w=445&quality=100&strip=all&ssl=1)
Source: https://randomnerdtutorials.com/esp32-esp8266-rgb-led-strip-web-server/
TODO:
* [ ] Add a relay

@ -1,8 +1,8 @@
// Define the pins for the LED strip
#define RED 23
#define RED 25
#define GREEN 33
#define BLUE 26
#define BLUE 32
void setup() {
@ -13,29 +13,43 @@ void setup() {
Serial.begin(9600);
}
// Print current values of the pins
void printValues() {
Serial.println("Red: " + String(analogRead(RED)));
Serial.println("Green: " + String(analogRead(GREEN)));
Serial.println("Blue: " + String(analogRead(BLUE)));
}
// Function that sets the color of the LED strip
void setColor(int red, int green, int blue) {
Serial.println("Setting color to: " + String(red) + ", " + String(green) + ", " + String(blue));
// Set the color of the LED strip
analogWrite(RED, red);
analogWrite(GREEN, green);
analogWrite(BLUE, blue);
printValues();
return;
}
void stop() {
// Function which turns off the pins
analogWrite(RED, 0);
analogWrite(GREEN, 0);
analogWrite(BLUE, 0);
Serial.println("Turning off the LED strip");
printValues();
return;
}
void loop() {
// Set the color to red
setColor(255, 0, 0);
delay(1000);
// Set the color to green
setColor(0, 255, 0);
delay(1000);
// Set the color to blue
setColor(0, 0, 255);
delay(1000);
// Set the color to white
// Alternate between off and white over 5 seconds
stop();
delay(5000);
setColor(255, 255, 255);
delay(1000);
// Set the color to off
setColor(0, 0, 0);
delay(1000);
delay(5000);
}