// https://wokwi.com/projects/425457835294261249
// Move the servo between two positions based on button presses
// See
// https://forum.arduino.cc/t/wokwi-simulations-for-arduino-built-in-examples/1304754/6
/*
################################################################################
# By DrCrowller #
# #
# Feel free to copy, modify and do whatever you want with this project #
# Be aware that the use of many variables may consume more memory than wanted #
# #
# Created : 7 Apr. 2022 #
################################################################################
*/
#include <Servo.h>
Servo arm; // Create a "Servo" object called "arm"
float pos = 0.0; // Variable where the arm's position will be stored (in degrees)
float step = 1.0; // Variable used for the arm's position step
void setup()
{
pinMode(A1, INPUT_PULLUP); // Set the A1 pin to a pushbutton in pullup mode
pinMode(A2, INPUT_PULLUP); // Set the A1 pin to a pushbutton in pullup mode
arm.attach(2); // Attache the arm to the pin 2
arm.write(pos); // Initialize the arm's position to 0 (leftmost)
}
void loop()
{
if (!digitalRead(A1)) // Check for the yellow button input
{
arm.write(0); // Set the arm's position to "pos" value
}
if (!digitalRead(A2)) // Check for the blue button input
{
arm.write(180); // Set the arm's position to "pos" value
}
}