#include <Stepper.h>
const int stepsPerRevolution = 200;
const int PRESST = LOW;
// initialize two steppers
Stepper motor1(stepsPerRevolution, 6, 7, 8, 9);
Stepper motor2(stepsPerRevolution, 10, 11, 12, 13);
void setup() {
Serial.begin(115200);
Serial.println("Helloo!\n");
motor1.setSpeed(18);
motor2.setSpeed(18);
pinMode(2, INPUT_PULLUP);
}
void loop() {
motor1.step(50);
motor2.step(-50);
waitOnButton();
motor1.step(-50);
motor2.step(50);
waitOnButton();
relayControl(3, HIGH);
waitOnButton();
relayControl(4, HIGH);
waitOnButton();
relayControl(3, LOW);
delay(1000);
relayControl(4, LOW);
delay(1000);
relayControl(5, HIGH);
delay(1000);
relayControl(5, LOW);
waitOnButton();
}
void waitOnButton()
{
Serial.println("Menunggu Tombol");
do delay(15); while (digitalRead(2) != PRESST);
while (digitalRead(2) == PRESST) delay(15);
delay(15);
}
void relayControl(unsigned char thePin, unsigned char theValue)
{
digitalWrite(thePin, theValue);
}
# define N15 111
void waitOnLongPress()
{
int count = 0;
Serial.println("waiting for a long press");
delay(15);
while (digitalRead(2) == PRESST) delay(15);
while (1) {
do delay(15); while (digitalRead(2) != PRESST);
count = 0;
do {
delay(15);
count++;
if (count > N15) return;
} while (digitalRead(2) == PRESST);
}
}
void waitOnButton0()
{
static unsigned long lastTime;
static unsigned char lastButton = HIGH;
unsigned long now;
Serial.println("a different waiting on the button");
for (; ; ) {
now = millis();
if (now - lastTime < 50) continue;
unsigned char thisButton = digitalRead(2);
if (thisButton != lastButton) {
lastButton = thisButton;
lastTime = now;
if (thisButton == PRESST) break;
}
}
}