From fbfcd8939912b37cff4e87610f20379656dd336c Mon Sep 17 00:00:00 2001 From: Boyan Date: Fri, 15 Mar 2024 01:19:50 +0100 Subject: [PATCH] Working on the LED strip. Almost done with the LED strip control. --- .gitignore | 1 + led_strip_door/README.md | 6 +++- led_strip_door/led_strip_door.ino | 48 ++++++++++++++++++++----------- 3 files changed, 37 insertions(+), 18 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..dbe9c82 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.vscode/ \ No newline at end of file diff --git a/led_strip_door/README.md b/led_strip_door/README.md index c820818..58a9667 100644 --- a/led_strip_door/README.md +++ b/led_strip_door/README.md @@ -1 +1,5 @@ -![WIRE](https://cdn.sparkfun.com/assets/learn_tutorials/7/9/0/Non_Addressable_LED_Strip_Simple_bb_Fritzing.png) \ No newline at end of file +![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 \ No newline at end of file diff --git a/led_strip_door/led_strip_door.ino b/led_strip_door/led_strip_door.ino index f7ea4b3..749f125 100644 --- a/led_strip_door/led_strip_door.ino +++ b/led_strip_door/led_strip_door.ino @@ -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); } \ No newline at end of file