//*
//Actual: Activity No. 2 - Controlling Servo motor
//Name: John Ronn Pahid
//Date Started: May 26, 2023
//Date Finished:
//Year & Section: BSMX - 3A - Night
//*/
//#include <Servo.h>
//Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
//#define servoPin 3
//#define pushButtonPin 2
//#define pushButtonPin 4
//int angle = 0;
//int angleStep = 15;
//const int minAngle = 0;
//const int maxAngle = 180;
//const int type = 1;
//int buttonPushed = 0;
//int pos = 0; // variable to store the servo position
//void setup() {
//Serial.begin(9600);
//myservo.attach(3); // attaches the servo on pin 3 to the servo object
//pinMode(pushButtonPin, INPUT_PULLUP);
//Serial.println("First Button");
//myservo.write(angle);
//}
//void loop() {
//if(digitalRead(pushButtonPin) == LOW) {
//buttonPushed = 1;
//}
//if (buttonPushed){
// change the angle for the next time through the loop:
//angle = angle + angleStep;
//if (angle >= maxAngle) {
//angleStep = -angleStep;
//if(type == 1)
//{
//buttonPushed = 0;
//}
//}
//if (angle <= minAngle){
//angleStep = -angleStep;
//if(type == 2)
//{
//buttonPushed = 0;
//}
//}
//myservo.write(angle);
//Serial.println("Moved to: ");
//Serial.print(angle);
//Serial.println(" degrees");
//delay(1000);
//}
//}
//*
//Actual: Activity No. 2 - Controlling Servo motor
//Name: John Ronn Pahid
//Date Started: May 26, 2023
//Date Finished:
//Year & Section: BSMX - 3A - Night
//*/
#include <Servo.h> // add servo library
Servo myservo; // create servo object to control a servo
int potpin = A1; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin
void setup() {
myservo.attach(3); // attaches the servo on pin 9 to the servo object
}
void loop() {
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}