ESP32 סרבו – פתיחה וסגירה \ נעול או פתוח בעזרת סרבו
https://wokwi.com/projects/369857352802240513
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#include "ESP32Servo.h" const int ledPin = 2; const int potentiometerPin = 32; const int servoPin = 4; Servo servo; void setup() { pinMode(ledPin, OUTPUT); pinMode(potentiometerPin, INPUT); servo.setPeriodHertz(50); servo.attach(servoPin); Serial.begin(115200); } void loop() { int potValue = analogRead(potentiometerPin); Serial.print("Potentiometer Value: "); Serial.println(potValue); if (potValue > 1000) { digitalWrite(ledPin, HIGH); // Turn on the LED servo.write(0); // Set servo position to 0 degrees } else { digitalWrite(ledPin, LOW); // Turn off the LED servo.write(180); // Set servo position to 180 degrees } delay(100); // Delay for stability } |