Вот что получилось
PHP код:
#include <Stepper.h>
#include <EEPROM.h>
#define motorSteps 24
#define motorPin1 8
#define motorPin2 9
#define motorPin3 10
#define motorPin4 11
int switchPin1 = 2;
int switchPin2 = 4;
int switchPin3 = 3;
int switchPin4 = 5;
int ledPin = 13;
int x;
int z;
int y;
int addr = 0;
boolean lastButton1 = LOW;
boolean currentButton1 = LOW;
boolean lastButton2 = LOW;
boolean currentButton2 = LOW;
boolean lastButton3 = LOW;
boolean currentButton3 = LOW;
boolean lastButton4 = LOW;
boolean currentButton4 = LOW;
Stepper myStepper(motorSteps, motorPin1,motorPin2,motorPin3,motorPin4);
void setup()
{
pinMode(switchPin1, INPUT);
pinMode(switchPin2, INPUT);
pinMode(switchPin3, INPUT);
pinMode(switchPin3, INPUT);
myStepper.setSpeed(200);
}
boolean debounce1(boolean last)
{
boolean current1 = digitalRead(switchPin1);
if (last != current1)
{
delay(5);
current1 = digitalRead(switchPin1);
}
return current1;
}
boolean debounce2(boolean last)
{
boolean current2 = digitalRead(switchPin2);
if (last != current2)
{
delay(5);
current2 = digitalRead(switchPin2);
}
return current2;
}
boolean debounce3(boolean last)
{
boolean current3 = digitalRead(switchPin3);
if (last != current3)
{
delay(5);
current3 = digitalRead(switchPin3);
}
return current3;
}
boolean debounce4(boolean last)
{
boolean current4 = digitalRead(switchPin4);
if (last != current4)
{
delay(5);
current4 = digitalRead(switchPin4);
}
return current4;
}
void loop()
{
{
//EEPROM.write(0, 0);
}
{
x=EEPROM.read(0);
}
currentButton1 = debounce1(lastButton1);
if (lastButton1 == LOW && currentButton1 == HIGH && x < 13)
{
myStepper.step(-24);
x = x + 1;
}
lastButton1 = currentButton1;
currentButton2 = debounce2(lastButton2);
if (lastButton2 == LOW && currentButton2 == HIGH && x > 0)
{
myStepper.step(24);
x = x - 1;
}
lastButton2 = currentButton2;
z = 13 - x;
currentButton3 = debounce3(lastButton3);
if (lastButton3 == LOW && currentButton3 == HIGH)
{
myStepper.step(-z*24);
x = x + z;
}
lastButton3 = currentButton3;
y = x;
currentButton4 = debounce4(lastButton4);
if (lastButton4 == LOW && currentButton4 == HIGH)
{
myStepper.step(y*24);
x = y - x;
}
lastButton4 = currentButton4;
x = min(x, 13);
x = max(x, 0);
{
EEPROM.write(0, x);
delay(100);
}
}