using pullstime

So I’m working on an Arduino project, specifically a project that would control an ESC. What I want to do is basically to use pulls time or millis to generate a PWM signal, that is firstly neutral for the ESC (1500) and when a button would be pushed it would add 200, so 1700, 1900. I have already made a code that makes a signal depending on a button, however, it is quite inconvenient to have 4 buttons under one hand, if this code would work I would basically just click the one button until the desired speed.

I have come this far, however, I am a complete amateur so I am having a lot of issues…

My code now:

Copy and paste your code. A picture of code will not compile. Use the </> button (in the control bar above the posting window) to mark your code as code.

include <Servo.h>

Servo m1;
int pushButton1 = A2;
int pushButton2 = A3;
int pullstime = millis;
int pushpulls = 10;

void setup() {
// put your setup code here, to run once:
šq+< ě m1.attach(9);
delay(1);
m1.write(40);

}

void loop() {
if (digitalRead(pushButton1) == HIGH > LOW) { //Opens the door when the ‘open’ button is pressed
m1.attach(9); //Gives the servo power
m1.writeMicroseconds(1500); //Tells servo to move to 0 degree mark
delay(1); // waits 1000ms for the servo to reach the position
} else {
m1.writeMicroseconds(1000);
delay(1);

{

if (digitalRead(pushButton2) == HIGH > LOW) { //Opens the door when the ‘open’ button is pressed
m1.attach(9); //Gives the servo power
m1.writeMicroseconds(2000); //Tells servo to move to 0 degree mark
delay(1); // waits 1000ms for the servo to reach the position
} else {
m1.writeMicroseconds(1000);
delay(1);

{

if (digitalRead(pushpulls) == HIGH > LOW) {
m1.attach(9);
m1.write( pullstime + 0.2)
or millis == 1500 + 0.2;

if (digitalRead(pushpulls) == HIGH > LOW) {
m1.attach(9);
m1.write( pullstime - 0.2);
or millis == 1500 - 0.2;

}
}
}
}
}
}

You should always use unsigned long variables with millis().

You can’t do fractions of a millisec (such as pullstime + 0.2). If you need a time interval shorter than 1 millisec use micros()

Whatever you think this is intended to do, it is wrong

if (digitalRead(pushpulls) == HIGH > LOW)

it should simply be

if (digitalRead(pushpulls) == HIGH)

You should attach your servos once in setup() - not repeatedly in loop()

And I’m sure there are other problems.

…R

PS … When posting code please use the code button </>

so your code looks like this

and is easy to copy to a text editor See How to use the Forum

I can't find the two arrows

Matyk:
I can’t find the two arrows

If you mean the </> icon, you need to be in Reply not Quick Reply, although you can enable the icons in Quick Reply by editin the settings in your Profile.

But if all you want to do is have one button increment something each time it's pressed, you could do worse than look at the State Change Detect example (also in the IDE at File > Examples...).

(Although the example shows the button wired to 5V with a pull down resistor to ground. Much easier to use the internal pullup, and a button press is then a low.)

# include <Servo.h>
Servo m1;
int pushButton1 = A2;
int pushButton2 = A3;
int pullstime = millis;
int pushpulls = 10;


void setup() {
  // put your setup code here, to run once:
  m1.attach(9);
  delay(1);
  m1.write(40);

}

void loop() {
  if (digitalRead(pushButton1) == HIGH) { //Opens the door when the 'open' button is pressed
    m1.attach(9);                     //Gives the servo power
    m1.writeMicroseconds(1500);                    //Tells servo to move to 0 degree mark
    delay(1);                       // waits 1000ms for the servo to reach the position
  } else {
    m1.writeMicroseconds(1000);
    delay(1);

    {

      if (digitalRead(pushButton2) == HIGH) { //Opens the door when the 'open' button is pressed
        m1.attach(9);                     //Gives the servo power
        m1.writeMicroseconds(2000);                  //Tells servo to move to 0 degree mark
        delay(1);                       // waits 1000ms for the servo to reach the position
      } else {
        m1.writeMicroseconds(1000);
        delay(1);

        {

          if (digitalRead(pushpulls) == HIGH)  {
            m1.attach(9);
            m1.write( pullstime + 0.2);



            {
              if (digitalRead(pushpulls) == HIGH)  {
                m1.attach(9);
                m1.write( pullstime - 0.2);


                }
              }
            }
          }
        }
      }
    }
  }[code]

[/code]

just please, I am the biggest and nubbiest beginner there can be, so could please simplify the expert help. Sorry

I have looked at the stage change detect and it looks good, but I don't know how I would tell it to change the pulse time (1500) with each click so that the ESC understands it

Matyk: but I don't know how I would tell it to change the pulse time (1500) with each click

In the example, the counter is incremented (just as an example of what you can do) each time the button is clicked. So in there, you do the same with your value, I forget what it's called, but something like:

myPulseTime = myPulseTime + pulseIncrement

.... kind of thing.

//The circuit:
 // - pushbutton attached to pin 2 from +5V
  //- 10 kilohm resistor attached to pin 2 from ground
 // - LED attached from pin 13 to ground (or use the built-in LED on most


 

// this constant won't change:
#include <Servo.h>
Servo m1;
const int  buttonPin = 2;  // the pin that the pushbutton is attached to
const int ledPin = 13;       // the pin that the LED is attached to

// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

void setup() {
  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
  // initialize the LED as an output:
  pinMode(ledPin, OUTPUT);
  // initialize serial communication:
  Serial.begin(9600);
}


void loop() {
  // read the pushbutton input pin:
  buttonState = digitalRead(buttonPin);


  // compare the buttonState to its previous state
  if (buttonState != lastButtonState) {
    // if the state has changed, increment the counter
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button went from off to on:
      buttonPushCounter++;
      Serial.println("on");
      Serial.print("number of button pushes: ");
      Serial.println(buttonPushCounter);
    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastButtonState = buttonState;


  // turns on the LED every four button pushes by checking the modulo of the
  // button push counter. the modulo function gives you the remainder of the
  // division of two numbers:
  if (buttonPushCounter % 1 == 0) { //Opens the door when the 'open' button is pressed
    m1.attach(9);                     //Gives the se
    m1.writeMicroseconds(1500);                  //Tells servo to move to 0 degree mark
    delay(1);                       // waits 1000ms for the servo to reach the position
  } else {
    m1.writeMicroseconds(1000);
    delay(1);

    if (buttonPushCounter % 2 == 0) { //Opens the door when the 'open' button is pressed
      m1.attach(9);                     //Gives the se
      m1.writeMicroseconds(1700);                  //Tells servo to move to 0 degree mark
      delay(1);                       // waits 1000ms for the servo to reach the position
    } else {
      m1.writeMicroseconds(1000);
      delay(1);

      if (buttonPushCounter % 3 == 0) { //Opens the door when the 'open' button is pressed
        m1.attach(9);                     //Gives the se
        m1.writeMicroseconds(2000);                  //Tells servo to move to 0 degree mark
        delay(1);                       // waits 1000ms for the servo to reach the position
      } else {
        m1.writeMicroseconds(1000);
        delay(1);


      }
    }
  }

}

 #include <Servo.h>
Servo m1;
int long unsigned
const int buttonPin = A2;
const int ledPin = 9;
const int myPulseTime = millis(1500);
const int pulseIncrement = millis(250);
const int myPulseTime = (myPulseTime + pulseIncrement);


int buttonPushCounter = 0;   // counter for the number of button presses
int buttonState = 0;         // current state of the button
int lastButtonState = 0;

void setup() {
/ initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
  // initialize the LED as an output:
  pinMode(ledPin, OUTPUT);
  // initialize serial communication:
  Serial.begin(9600);

}

void loop() {
  buttonState = digitalRead(buttonPin);

  if (buttonPushCounter % 1 == 0 {
  m1.attach(9);
    m1.write myPulseTime = (myPulseTime + pulseIncrement);
    delay(1);
  } else {
    m1.writeMicroseconds(1000);
    delay(1);



    if (buttonPushCounter % 2 == 0) {
      m1.attach(9);
      m1.write myPulseTime = (myPulseTime + pulseIncrement);
      delay(1);
    } else {
      m1.writeMicroseconds(1000);
      delay(1);



      if (buttonPushCounter % 3 == 0) {
        m1.attach(9);
        m1.write myPulseTime = (myPulseTime + pulseIncrement);
        delay(1);
      } else {
        m1.writeMicroseconds(1000);
        delay(1);





      }
    }
  }
}

[/quote]

go this far but it keeps giving me this message: "two or more data types in declaration of 'buttonPin'"

int long unsigned
const int buttonPin = A2;

What is the first line above supposed to do ?

  if (buttonPushCounter % 1 == 0 {

No closing bracket on the if

In any case, the remainder when dividing an integer by 1 will always be zero

If I don't say that the int long unsigned gives me this: too many arguments to function 'long unsigned int millis()'

Stop thrashing about and think logically.

For instance

const int myPulseTime = millis(1500);

millis() returns a value. What is the 1500 about ?

it is 15 milliseconds, if the ESC gets 1500 it does not output any speed, 1500- 2000 is the actual speed

and do you know how I could solve the: two or more data types in declaration of 'buttonPin'