From acc555fa0ad94a522cede545986219867c5758e2 Mon Sep 17 00:00:00 2001 From: Manuel Weiser Date: Tue, 1 May 2018 21:18:12 +0200 Subject: [PATCH] Switch back to Arduino Mega and added Endstop and Waycounter. --- platformio.ini | 4 ++-- src/main.cpp | 53 ++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/platformio.ini b/platformio.ini index 46e43ec..439e28f 100644 --- a/platformio.ini +++ b/platformio.ini @@ -10,6 +10,6 @@ [env:arduino] platform = atmelavr -//board = megaatmega2560 -board = uno +board = megaatmega2560 +//board = uno framework = arduino diff --git a/src/main.cpp b/src/main.cpp index 67211dd..60aad5a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -13,7 +13,7 @@ #define btnSELECT 4 #define btnNONE 5 -unsigned int lowSpeed = 10000; // Notabene: nicht über 16000 +unsigned int lowSpeed = 6000; // Notabene: nicht über 16000 unsigned int highSpeed = 1000; @@ -21,13 +21,16 @@ unsigned int highSpeed = 1000; LiquidCrystal lcd(8,9,4,5,6,7); // Then the pins are entered here in the sequence 1-3-2-4 for proper sequencing -Stepper bigStepper(bigStepperStepsRev, 20, 21); +Stepper bigStepper(bigStepperStepsRev, 30, 31); // Setup small Stepper -const int motorPin1 = 51; // Blue - In 1 -const int motorPin2 = 52; // Pink - In 2 -const int motorPin3 = 53; // Yellow - In 3 -const int motorPin4 = 54; // Orange - In 4 +const int motorPin1 = 32; // Blue - In 1 +const int motorPin2 = 34; // Pink - In 2 +const int motorPin3 = 36; // Yellow - In 3 +const int motorPin4 = 38; // Orange - In 4 + +// Setup Endstop +const int endStop = 33; /*-----( Declare Variables )-----*/ // Big Stepper 1 Revolution = 6400 Steps @@ -42,6 +45,8 @@ bool startWind = false; int whenJump = 3; int wideJump = 10; float servoPos = 0; +bool goLeft = true; +int leftSteps = 0; void setup() { @@ -53,6 +58,8 @@ void setup() pinMode(motorPin3, OUTPUT); pinMode(motorPin4, OUTPUT); + pinMode(endStop, INPUT); + // set up the LCD ////////////////////// lcd.begin(2, 16); // Set the size of the LCD lcd.clear(); // Clear the screen @@ -170,7 +177,7 @@ void linksrum(unsigned int motorSpeed) digitalWrite(motorPin4, LOW); delayMicroseconds(motorSpeed); - // 4 + // 4 digitalWrite(motorPin1, LOW); digitalWrite(motorPin2, HIGH); digitalWrite(motorPin3, HIGH); @@ -264,7 +271,7 @@ void loop() if (startWind == true) { if (revCounter < whenJump) { - moveBigStepper(1, 1000); + moveBigStepper(1, 500); bigStepCounter++; if (bigStepCounter == bigRev) { @@ -273,11 +280,33 @@ void loop() } } else { - for (int i=0; i<=wideJump; i++) { - moveBigStepper(1, 1000); - - rechtsrum(lowSpeed); + // Endstop auslesen und Richtung bestimmen + if (digitalRead(endStop) == false) { + goLeft = false; } + else if (goLeft == true) { + leftSteps++; + } + + for (int i=0; i<=wideJump; i++) { + moveBigStepper(1, 500); + + if (goLeft == false && leftSteps > 0) { + rechtsrum(highSpeed); + } + else { + linksrum(highSpeed); + } + } + + if (goLeft == false && leftSteps > 0) { + leftSteps--; + } + if (goLeft == false && leftSteps == 0) { + goLeft = true; + } + + Serial.println(leftSteps); revCounter = 0; } }