/*
################################################################################
# Popper ASG v1.0 [STAND ALONE VERSION 1] #
# by Sir Tedi #
# #
# Created : 04.05.2023 #
################################################################################
*/
#include <Servo.h>
#define GP1 1 // pin servo
#define GP2 2 // pin BLUE
#define GP4 4 // pin RGB - R
#define GP9 9 // pin RGB - G
Servo arm; // Utworzenie obiektu "Servo" o nazwie "arm"
int pos = 90.0; // Zmienna określająca pozycje "arm" w stopniach
int step = 1.0; // Zmienna określająco o ile zmienia sie kąt
byte dir = 0; // Zmienna decydująca o kierunku ruchu servo (0 - w lewo, 1 - w prawo)
byte popper = 0; // Zmienna informująca o upadku poppera (0 - stoi, 1 - opadł)
void setup()
{
/* PRZYCISKI */
pinMode(GP2, INPUT_PULLUP); // Przycisk BLUE podpięty do A1 pin - INICJACJA RUCHU arm
/* DIODA */
pinMode(GP4, OUTPUT); //pin RGB - R
pinMode(GP9, OUTPUT); //pin RGB - G
digitalWrite(GP4, LOW);
digitalWrite(GP9, HIGH);
/* SERVO */
arm.attach(GP1); // Attache the arm to the pin 2
arm.write(pos); // Initialize the arm's position to 180
}
void loop()
{
if (!digitalRead(GP2)) // Check for the blue button input
{
popper = 1;
}
if (popper==1) // Czy popper leży?
{
digitalWrite(GP4, HIGH);
digitalWrite(GP9, HIGH);
delay(1000); // opóźnienie resetu
digitalWrite(GP4, HIGH);
digitalWrite(GP9, LOW);
if (dir==0) // Jeżeli ruch ma być w lewo
{
while (pos > 0) // 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
{
delay(500); // Wait 500ms for the arm to reach the position
while (pos < 90) // Dopóki kąt jest mniejszy niż 180° idz w prawo
{
arm.write(pos); // Set the arm's position to "pos" value
pos+=step; // Increment "pos" of "step" value
delay(3); // Wait 3ms for the arm to reach the position
}
dir=0;
popper=0;
digitalWrite(GP4, LOW);
digitalWrite(GP9, HIGH);
}
}
}