/*
################################################################################
# Popper ASG v0.1 [Stand alone version] #
# #
# #
# Created : 25.04.2023 zmodyfikowany projekt DrCrowller #
################################################################################
*/
#include <Servo.h>
Servo arm; // Utworzenie obiektu "Servo" o nazwie "arm"
float pos = 180.0; // Zmienna określająca pozycje "arm" w stopniach
float step = 1.0; // Zmienna określająco o ile zmienia sie kąt
int dir = 0; // Zmienna decydująca o kierunku ruchu servo (0 - w lewo, 1 - w prawo)
int popper = 0; // Zmienna informująca o upadku poppera (0 - stoi, 1 - opadł)
void setup()
{
pinMode(A2, INPUT_PULLUP); // Przycisk podpięty do A2 pin - OPAD POPPERA
arm.attach(2); // Attache the arm to the pin 2
arm.write(pos); // Initialize the arm's position to 180
}
void loop()
{
if (!digitalRead(A2)) // Check for the yellow button input
{
popper = 1;
}
{ // Procedura podnoszenia poppera
if (popper==1) // Czy popper leży?
{
delay(500); // Wait 500ms
if (dir==0) // Jeżeli ruch ma być w lewo
{
while (pos > 88) // Dopóki kąt jest większy niż 0° idz w lewo
{
arm.write(pos); // Set the arm's position to "pos" value
pos-=step; // Decrement "pos" of "step" value
delay(3); // Wait 3ms for the arm to reach the position
}
dir=1;
}
if (dir==1) // Jeżeli ruch ma być w prawo
{
while (pos < 180) // Dopóki kąt jest mniejszy niż 180° idz w prawo
{
arm.write(pos); // Set the arm's position to "pos" value
pos+=step; // Decrement "pos" of "step" value
delay(3); // Wait 3ms for the arm to reach the position
}
dir=0;
popper=0; // Popper stoi
}
}
}
}