How to reset the position?

// Include the AccelStepper Library
#include <AccelStepper.h>

// Creates an instance
// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
AccelStepper myStepper(AccelStepper::FULL4WIRE, 4, 6, 5, 7);
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxxxxxxxxxxx";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxxxxxxx";
char pass[] = "xxxxxxxxxxx";

// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial1

// or Software Serial on Uno, Nano...
//#include <SoftwareSerial.h>
//SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);



void setup()

{
  Serial.begin(9600);
  EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
}

 
BLYNK_WRITE(V0)   // Slider in V0
 
    {
      int cup_slider = param.asInt();
      
      // set the maximum speed, acceleration factor,
      // initial speed and the target position

      cup_slider = param.asInt();
      {
       
        myStepper.setMaxSpeed(1000.0);
        myStepper.setAcceleration(100.0);
        myStepper.setSpeed(300.0);
        myStepper.moveTo((cup_slider) *2048ul);
        // aqui serve para setar o numero de voltas que o motor
        // vai dar, então no caso é melhor que marcar o tempo
        // em minutos 1 volta=2038

      }
    }
  

  
void loop() {
      {
     
       // Move the motor one step each time through loop()
        myStepper.run();
        Serial.println(myStepper.currentPosition());
        Blynk.run();
  }
 }
  

the cup_slider variable
in fact what I also realized is that when I sit 4 laps and then 2, it turns in the opposite direction to complete what is missing
another thing I noticed is that there is no way with this code I for example, on the slider put the limit as 5 and if I want to do 10 laps, I have no way to set it to give 5 laps 2x for example can that specific part be solved?
now i have one more question, after setting the engine to give two times for example, after it finishes, if i want to set it to give 4 laps for example, it only advances + two laps to complete the 4, could you tell me what it would be like to reset the zero position after finishing the laps?

This code

// Include the AccelStepper Library
#include <AccelStepper.h>

// Creates an instance
// Pins entered in sequence IN1-IN3-IN2-IN4 for proper step sequence
AccelStepper myStepper(AccelStepper::FULL4WIRE, 4, 6, 5, 7);
/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <ESP8266_Lib.h>
#include <BlynkSimpleShieldEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "xxxxxxxxxx";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxx";
char pass[] = "xxxxxxxxx";

// Hardware Serial on Mega, Leonardo, Micro...
#define EspSerial Serial1

// or Software Serial on Uno, Nano...
//#include <SoftwareSerial.h>
//SoftwareSerial EspSerial(2, 3); // RX, TX

// Your ESP8266 baud rate:
#define ESP8266_BAUD 9600

ESP8266 wifi(&EspSerial);


 
void setup()

{
  Serial.begin(9600);
   EspSerial.begin(ESP8266_BAUD);
  delay(10);

  Blynk.begin(auth, wifi, ssid, pass);
  }
BLYNK_WRITE(V0)   // Slider in V0
{
 int cup_slider = param.asInt();
  // set the maximum speed, acceleration factor,
  // initial speed and the target position
  
 if (cup_slider = param.asInt()== 1)
 { 
  myStepper.setMaxSpeed(1000.0);
  myStepper.setAcceleration(100.0);
  myStepper.setSpeed(100.0);
  myStepper.moveTo((cup_slider) * 2048ul);
  // aqui serve para setar o numero de voltas que o motor 
  // vai dar, então no caso é melhor que marcar o tempo 
  // em minutos 1 volta=2038

}

void loop(){
{
  // Move the motor one step each time through loop()
  myStepper.run();
  Serial.println(myStepper.currentPosition());
}
}

make me an error
C: \ Users \ gabri \ OneDrive \ test_motorzin \ mano_for_testing_motor \ motor_of_variables_voltas.ino: In function ‘void BlynkWidgetWrite0 (BlynkReq &, const BlynkParam &)’:
motor_da_varias_voltas: 64: 12: error: a function-definition is not allowed here before ‘{’ token
void loop () {
^
motor_da_varias_voltas: 70: 1: error: expected ‘}’ at end of input
}
^
Multiple libraries were found for “BlynkSimpleShieldEsp8266.h”
Used: C: \ Users \ gabri \ OneDrive \ Documents \ Arduino \ libraries \ Blynk
Not used: C: \ Users \ gabri \ OneDrive \ Documents \ Arduino \ libraries \ blynk-library-master
exit status 1
a function-definition is not allowed here before ‘{’ token

but I don’t know exactly where I’m wrong, another thing I’d like to ask is if anyone knows how I can use the value that comes out of BLYNK_WRITE (V0) (which is a slider in the blynk app) to pass to cup_slider and thus be able to multiply by 2048 down there
thank you very much for your attention, and forgive the “silly” doubts

Where does the BLYNK_WRITE() function end ?

Auto Format the code in the IDE and you will see that the loop() function does not start on the left margin as it should.

A missing } perhaps ?

ok, it was what i needed, auto format and it worked after some changes, now i have one more question, after setting the engine to give two times for example, after it finishes, if i want to set it to give 4 laps for example, it only advances + two laps to complete the 4, could you tell me what it would be like to reset the zero position after finishing the laps?

What is it that sets the number of times to 2 ?

the cup_slider variable
in fact what I also realized is that when I sit 4 laps and then 2, it turns in the opposite direction to complete what is missing
another thing I noticed is that there is no way with this code I for example, on the slider put the limit as 5 and if I want to do 10 laps, I have no way to set it to give 5 laps 2x for example (but I think this one part in specific I can solve)

Your two topics on the same subject have been merged

1 Like

thank you very much, sorry for repeating the subject but it is that now I am bumping into another part and I couldn’t find a solution for this, even though I am studying C ++ I still couldn’t find a way to do it in a correct way (reset the position of the motor so that it does not turn in the opposite direction)

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.