// Init
int xyzPins[] = {13, 12, 14}; //x,y,z pins
int servoPin = 15; // Servo motor pin
int posVal = 90; // variable to store the servo position
int posTemp = 90;
int DZMin = 2000;
int DZMax = 2100;
int Dif = 0;
int DLY = 20;
int CValue = 0;
byte btn_prev;
int StepNum = 1;
int StepDelay = 1;
// Define
#define buttonPin 2
#define LEDPin 3
#define STEP 8
#define POT 4
void OneStep(void){
digitalWrite(STEP, HIGH);
digitalWrite(STEP, LOW);
}
void MultiStep(void){
for(int i = 0; i < StepNum; i += 1){
OneStep();
delay(StepDelay);
}
}
void setup() { // Start of Setup
pinMode(buttonPin, INPUT_PULLUP);
pinMode(buttonPin, INPUT);
pinMode(LEDPin, OUTPUT);
pinMode(STEP, OUTPUT);
btn_prev = digitalRead(buttonPin);
digitalWrite(LEDPin,LOW);
Serial.begin( 9600);
}
void loop() { // Start of the loop
byte btn = digitalRead(buttonPin);
if (btn == LOW && btn_prev == HIGH) {
if (CValue == 0) {
CValue = 1;
digitalWrite(LEDPin, HIGH);
MultiStep();
Serial.print(CValue);
}
else {
CValue = 0;
digitalWrite(LEDPin, LOW);
MultiStep();
Serial.print(CValue);
}
}
btn_prev = btn;
delay(DLY);
} // End of the loop