Goofing around with the new ESP32 module
Not a member? You should Sign up.
Already have an account? Log in.
To make the experience fit your profile, pick a username and tell us what interests you.
Please forgive this messy code, I was just goofing around and did not plan on sharing it, but here I am sharing it. LOL
#include <WiFi.h> const char* ssid = "(Your WiFi Access Point Name)"; const char* password = "(Your WiFi Access Point Password)"; int ledPin = 4; WiFiServer server(80); //---------------------------------- #include "esp32-hal-ledc.h" uint32_t maxint = 65535; uint32_t servoMax = 8000; uint32_t servoMin = 1700; uint32_t servoLow = servoMin; //1700 + 1300; uint32_t servoHigh = 1700 + 1000 + 1300; //servoLow+1000; uint32_t servoCenter = (servoLow + servoHigh) / 2; const byte numberOfServos = 12; byte servoPins[numberOfServos] = {5, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23}; char command = 0; void setupServo() { for (byte servoIndex = 0; servoIndex < numberOfServos; servoIndex++) { byte channel = servoIndex; byte servoPin = servoPins[servoIndex]; ledcSetup(channel, 50, 16); // channel X, 50 Hz, 16-bit depth ledcAttachPin(servoPin, channel); // GPIO servoPin on channel X ledcWrite(channel, servoHigh); //servoMin } delay(2000); } //---------------------------------- void setup() { Serial.begin(115200); pinMode(ledPin, OUTPUT); // set the LED pin mode delay(10); // We start by connecting to a WiFi network Serial.println(); Serial.println(); Serial.print("Connecting to "); Serial.println(ssid); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println(""); Serial.println("WiFi connected"); Serial.println("IP address: "); Serial.println(WiFi.localIP()); server.begin(); setupServo(); } void Marching() { for (byte servoIndex = 0; servoIndex < numberOfServos; servoIndex++) { byte channel = servoIndex; ledcWrite(channel, servoHigh); } delay(500); for (byte servoIndex = 0; servoIndex < numberOfServos; servoIndex++) { byte channel = servoIndex; ledcWrite(channel, servoLow); } delay(500); } void LeftToRight(int servoValue, int dly) { for (int head = 0; head < numberOfServos; head++) { if (head >= 0 && head < numberOfServos) ledcWrite(head, servoValue); delay(dly); } } void RightToLeft(int servoValue, int dly) { for (int head = numberOfServos - 1; head >= 0 ; head--) { if (head >= 0 && head < numberOfServos) ledcWrite(head, servoValue); delay(dly); } } void SpreadOut(int dly) { int half = (numberOfServos / 2); for (int i = 0; i <= half ; i++) { int left = half - i; int right = half + i; if (left >= 0 && left < numberOfServos) ledcWrite(left, servoHigh); if (right >= 0 && right < numberOfServos) ledcWrite(right, servoLow); delay(dly); } } void SpreadOutRestore(int dly) { int half = (numberOfServos / 2); for (int i = 0; i <= half ; i++) { int left = half - i; int right = half + i; if (left >= 0 && left < numberOfServos) ledcWrite(left, servoCenter); if (right >= 0 && right < numberOfServos) ledcWrite(right, servoCenter); delay(dly); } } void OutIn(int dly) { int half = (numberOfServos / 2); for (int i = 0; i <= half ; i++) { int left = (numberOfServos - 1) - i; int right = i; if (left >= 0 && left < numberOfServos) ledcWrite(left, servoCenter); if (right >= 0 && right < numberOfServos) ledcWrite(right, servoCenter); delay(dly); } } int value = 0; void SendHtmlResponse(WiFiClient client) { // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK) // and a content-type so the client knows what's coming, then a blank line: client.println("HTTP/1.1 200 OK"); client.println("Content-type:text/html"); client.println(); // the content of the HTTP response follows the header: client.print("<h1 style='font-size:400%;'>"); client.print("<a href='/'>Home</a><br>"); client.print("Left to Right: <a href='/A'>\\\</a> <a href='/B'>///</a><br>"); client.print("Right to Left: <a href='/C'>\\\</a> <a href='/D'>///</a><br>"); client.print("All: <a href='/E'>\\\</a> <a href='/H'>Center</a> <a...
View project log
Create an account to leave a comment. Already have an account? Log In.
Awesome demo Hari. I have completed many projects with the esp8266 and look forward to working with the esp32
Are you sure? yes | no
erhanyilmaz.ytu
jareklupinski
Simon Jansen
Paul Scott
Become a member to follow this project and never miss any updates
By using our website and services, you expressly agree to the placement of our performance, functionality, and advertising cookies. Learn More
Yes, delete it Cancel
You are about to report the project "HariFun #150 Playing with ESP32", please tell us the reason.
Your application has been submitted.
Are you sure you want to remove yourself as a member for this project?
Project owner will be notified upon removal.
Awesome demo Hari. I have completed many projects with the esp8266 and look forward to working with the esp32