Differences

This shows you the differences between two versions of the page.

Link to this comparison view

iothings:laboratoare:2022:lab3 [2022/10/20 20:57]
dan.tudose
iothings:laboratoare:2022:lab3 [2025/03/13 19:34] (current)
andreea.miu [SPIFFS Webserver] add ledPin tip
Line 1: Line 1:
 ===== Lab 3: Web servers ===== ===== Lab 3: Web servers =====
- 
-==== Web Server ==== 
  
 In this project we'll program the ESP32 Sparrow board to act as a web server on your local network and deliver a simple web page where you can control the on-board RGB led. The web server is mobile responsive and can be accessed with any device that can open a browser in the local network. In this project we'll program the ESP32 Sparrow board to act as a web server on your local network and deliver a simple web page where you can control the on-board RGB led. The web server is mobile responsive and can be accessed with any device that can open a browser in the local network.
Line 11: 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.
- 
- 
 <code C webserver.ino>​ <code C webserver.ino>​
 // Load Wi-Fi library // Load Wi-Fi library
Line 231: 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 238: 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 264: 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(outputledChannel);+  ​ledcAttach(ledPinfreq, resolution);
   ​   ​
-  ledcWrite(ledChannel, sliderValue.toInt());​+  ledcWrite(ledPin, sliderValue.toInt());​
  
   // Connect to Wi-Fi   // Connect to Wi-Fi
Line 296: 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 313: 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 375: 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 ===
iothings/laboratoare/2022/lab3.1666288623.txt.gz · Last modified: 2022/10/20 20:57 by dan.tudose
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0