// https://wokwi.com/projects/407839613671092225
// Name: Chan Tai Man
// No.: 24XXXXXXX
// Class: EGX14403/1X
// Program: 1X_Ex2_Q1_ChanTaiMan.ino, 1X_Ex3_Q2_ChanTaiMan.ino (for example)
/*
- Declare variables/constants in a meaningful way
- Remember to include explanatory comments/remarks/annotations
- Ensure proper block organization and readability of the source code
(e.g., through indentation)
- Remove any irrelevant comments/code (** Including this section **)
- Run the program at least once before submitting it
- Use Ctrl+A and Ctrl+C to copy the entire program
- Use Ctrl+V to paste the selected text into Notepad
- Save the file as "1X_Ex2_Q1_ChanTaiMan.ino" or "1X_Ex3_Q2_ChanTaiMan.ino" (for example)
- Upload the file to Moodle
*/
#include <ESP32Servo.h>
int val = 0;
int potVal = 0;
int buttonPin = 14;
int analogPin = 33;
const int servoPin = 18;
Servo robot_servo;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(buttonPin, INPUT);
robot_servo.attach(servoPin, 500, 2400);
}
void loop() {
// put your main code here, to run repeatedly:
delay(100); // this speeds up the simulation
val = digitalRead(buttonPin);
potVal = analogRead(analogPin);
Serial.print("Button switch status is ");
Serial.print(val);
Serial.print(", POT status is ");
Serial.println(potVal);
robot_servo.write(map(potVal, 0, 4095, 0, 180));
// if(val == 0){
// robot_servo.write(180);
// }
// else{
// robot_servo.write(0);
// }
}