From 3378960dc5115f2206441c37a9bed753f6d2efd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= Date: Tue, 20 Jun 2017 23:10:32 +0200 Subject: [PATCH] some cleaning + initial code for reset position remove dead code commented out initial routine for reseting position on long press --- arduino/startracker.ino | 175 ++++++---------------------------------- 1 file changed, 24 insertions(+), 151 deletions(-) diff --git a/arduino/startracker.ino b/arduino/startracker.ino index ea54756..86d6360 100644 --- a/arduino/startracker.ino +++ b/arduino/startracker.ino @@ -19,6 +19,8 @@ static const unsigned int m2_pin = 7; static const unsigned int enable_pin = led_pin; +static const unsigned int long_press_threshold_ms = 1000; + // using a 200-step motor (most common) // pins used are DIR, STEP, MS1, MS2, MS3 in that order //A4988 stepper(200, 8, 9, 10, 11, 12); @@ -136,27 +138,10 @@ static const int fake_start = 1; #define CLR(x,y) (x&=(~(1<= long_press_threshold_ms)) { + long_press = 1; + } + } + } + if (long_press){ + control_state = RESET_POSITION; + } else { + control_state = RUN; + start_timer(global_period); + } } break; @@ -313,6 +310,12 @@ void control_automata(void) { } break; + + case RESET_POSITION: + while(digitalRead(end_stop_pin) == LOW){ + stepper.move(-1); + } + break; } #if DEBUG == 2 @@ -321,36 +324,6 @@ void control_automata(void) { } - -/* void setRpm() */ -/* { */ -/* float temp; */ -/* if (rpm == 0) */ -/* { */ -/* ICR1 = ZERO_SPEED; */ -/* digitalWrite(enable_pin, HIGH); // Disable motor */ -/* } */ -/* else */ -/* { */ -/* digitalWrite(enable_pin, LOW); // Enable motor */ -/* /\* if (rpm<8) */ -/* rpm = 8;*\/ */ -/* if (rpm>MAX_RPM) */ -/* rpm = MAX_RPM; */ -/* temp = (rpm/60.0)*STEPS_PER_REV; // Number of steps per seconds needed */ -/* temp = 2000000 / temp; // 2000000 = (16000000/8) timer1 16Mhz with 1/8 preescaler */ -/* if (period<600000) */ -/* period=60000; */ -/* period = temp; */ -/* while (TCNT1 < 30); // Wait until a pulse to motor has finished */ -/* //cli(); */ -/* ICR1 = period; //+ userCommand; */ -/* if (TCNT1 > ICR1) // Handle when we need to reset the timer */ -/* TCNT1=0; */ -/* //sei(); */ -/* } */ -/* } */ - void setup() { // debug output Serial.begin(serial_speed); @@ -370,45 +343,15 @@ void setup() { // Setup PIN as GPIO output pinMode(led_pin, OUTPUT); // LED pin - - /* pinMode(step_pin, OUTPUT); // STEP pin */ - /* pinMode(dir_pin, OUTPUT); // DIR pin */ - - // pinMode(enable_pin, OUTPUT); // ENABLE pin - - /* digitalWrite(dir_pin, HIGH); // Motor direction */ - /* digitalWrite(step_pin, HIGH); */ - /* while(1); */ - // Button input with pullups enable pinMode(btn1_pin, INPUT_PULLUP); pinMode(btn2_pin, INPUT_PULLUP); pinMode(btn3_pin, INPUT_PULLUP); // Initial setup for motor driver - // digitalWrite(enable_pin, HIGH); // Disable motor - /* digitalWrite(dir_pin, HIGH); // Motor direction */ - digitalWrite(led_pin, HIGH); delay(200); // Initial delay digitalWrite(led_pin, LOW); - - motor_enable = false; - - /* // PWM SETUP */ - /* // Fast PWM mode => TOP:ICR1 */ - /* TCCR1A =(1<