This shows you the differences between two versions of the page.
iothings:laboratoare:2022:lab3 [2023/10/23 19:18] dan.tudose [Lab 3: Web servers] |
iothings:laboratoare:2022:lab3 [2025/03/13 19:34] (current) andreea.miu [SPIFFS Webserver] add ledPin tip |
||
---|---|---|---|
Line 9: | Line 9: | ||
Run this example code on your board, but replace the SSID and PASSWORD fields with your own. | Run this example code on your board, but replace the SSID and PASSWORD fields with your own. | ||
- | <codedoc code> | + | <code C webserver.ino> |
// Load Wi-Fi library | // Load Wi-Fi library | ||
#include <WiFi.h> | #include <WiFi.h> | ||
Line 182: | Line 182: | ||
} | } | ||
} | } | ||
- | </codedoc> | + | </code> |
Test the code works in your phone's or computer's browser and switch on/off the LEDs. | Test the code works in your phone's or computer's browser and switch on/off the LEDs. | ||
Line 227: | Line 227: | ||
const char* ssid = "REPLACE_WITH_YOUR_SSID"; | const char* ssid = "REPLACE_WITH_YOUR_SSID"; | ||
const char* password = "REPLACE_WITH_YOUR_PASSWORD"; | const char* password = "REPLACE_WITH_YOUR_PASSWORD"; | ||
- | |||
- | const int output = 14; //red led | ||
String sliderValue = "0"; | String sliderValue = "0"; | ||
Line 234: | Line 232: | ||
// setting PWM properties | // setting PWM properties | ||
const int freq = 5000; | const int freq = 5000; | ||
- | const int ledChannel = 0; | + | const int ledPin = 14; // red led |
const int resolution = 8; | const int resolution = 8; | ||
Line 260: | Line 258: | ||
return; | return; | ||
} | } | ||
- | // configure LED PWM functionalitites | ||
- | ledcSetup(ledChannel, freq, resolution); | ||
| | ||
- | // attach the channel to the GPIO to be controlled | + | // configure LED PWM & attach the channel to the GPIO to be controlled |
- | ledcAttachPin(output, ledChannel); | + | ledcAttach(ledPin, freq, resolution); |
| | ||
- | ledcWrite(ledChannel, sliderValue.toInt()); | + | ledcWrite(ledPin, sliderValue.toInt()); |
// Connect to Wi-Fi | // Connect to Wi-Fi | ||
Line 292: | Line 288: | ||
sliderValue = inputMessage; | sliderValue = inputMessage; | ||
Serial.println(sliderValue.toInt()); | Serial.println(sliderValue.toInt()); | ||
- | ledcWrite(ledChannel, 255 - sliderValue.toInt()); | + | ledcWrite(ledPin, 255 - sliderValue.toInt()); |
} | } | ||
else { | else { | ||
Line 309: | Line 305: | ||
} | } | ||
</code> | </code> | ||
+ | |||
+ | <note tip> | ||
+ | Change the //ledPin// according to your board version. | ||
+ | |||
+ | For the GREEN boards: Red - GPIO25, Green - GPIO26, Blue - GPIO27 | ||
+ | |||
+ | For the BLUE boards: Red - GPIO14, Green - GPIO13, Blue - GPIO15 | ||
+ | </note> | ||
Line 371: | Line 375: | ||
== Assignment == | == Assignment == | ||
- | <note> Modify the webserver sketch to receive data from the other two sliders in the webpage and control the other two PWM channels (13 - green and 15 - blue).</note> | + | <note> Modify the webserver sketch to receive data from the other two sliders in the webpage and control the other two PWM channels (green and blue).</note> |
=== Live charts === | === Live charts === |