Go Down

Topic: using pullstime  (Read 1 time) previous topic - next topic

UKHeliBob

Code: [Select]
  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
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Matyk

#16
Mar 22, 2019, 11:34 am Last Edit: Mar 22, 2019, 11:35 am by Matyk
If I don't say that the int long unsigned gives me this: too many arguments to function 'long unsigned int millis()'

UKHeliBob

Stop thrashing about and think logically.

For instance
Code: [Select]
const int myPulseTime = millis(1500);
millis() returns a value.  What is the 1500 about ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Matyk

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

Matyk

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

Matyk

// Should it be like this




Code: [Select]
#include <Servo.h>
Servo m1;
int unsigned long
const int buttonPin = A2;
const int ledPin = 9;
const int myPulseTime = writeMicroseconds(1500);
const int pulseIncrement = writeMicroseconds(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);





      }
    }
  }
}


UKHeliBob

Quote
// Should it be like this
No

buttonPin is presumably the number of a pin.  It will not change in the program and it will not have a value of greater than 255 so a byte will be large enough to hold the value

So it should be
Code: [Select]
const byte buttonPin = A2;
and delete the previous line
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Matyk

did that thanks man, but I still get the "too many arguments to function 'long unsigned int millis()'" if i delete the thing.

johnwasser

Code: [Select]
const int myPulseTime = writeMicroseconds(1500);
const int pulseIncrement = writeMicroseconds(250);
const int myPulseTime = (myPulseTime + pulseIncrement);


You are trying to declare "myPulseTime" as two different constants.  One of those will have to change names.

writeMicroseconds(1500) is not a constant.  Use 1500 instead.
writeMicroseconds(250) is not a constant.  Use 250 instead.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

Matyk

Thanks so much, everything is working, but the damn thing is now saying: expected ';' before 'myPulsetime'
at the last segment ( the part before the special symbols).

Matyk

Code: [Select]
#include <Servo.h>
Servo m1;
const byte buttonPin = A2;
const int ledPin = 9;
const int mypulseTime =  (1500);
const int pulseIncrement = (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);





      }
    }
  }
}



UKHeliBob

Thanks so much, everything is working, but the damn thing is now saying: expected ';' before 'myPulsetime'
at the last segment ( the part before the special symbols).
It can't be working if you are still getting errors while compiling

Post the code as it is now and the full error message
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Matyk

#27
Mar 22, 2019, 08:58 pm Last Edit: Mar 22, 2019, 09:48 pm by Matyk
#include <Servo.h>
Servo m1;
const byte buttonPin = A2;
const int ledPin = 9;
const int mypulseTime =  (1250);
const int pulseIncrement = (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);





      }
    }
  }
}


Arduino: 1.8.7 (Mac OS X), Board: "Arduino/Genuino Uno"

/Users/matyaskloc/Desktop/ESC-ARDUINO-CONTROL/ANother_one/ANother_one.ino: In function 'void loop()':
ANother_one:29:14: error: expected ';' before 'myPulsetime'
     m1.write myPulsetime = (mypulseTime + pulseIncrement);
              ^
ANother_one:29:58: error: invalid use of non-static member function
     m1.write myPulsetime = (mypulseTime + pulseIncrement);
                                                          ^
ANother_one:39:16: error: expected ';' before 'myPulsetime'
       m1.write myPulsetime = (mypulseTime + pulseIncrement);
                ^
ANother_one:39:60: error: invalid use of non-static member function
       m1.write myPulsetime = (mypulseTime + pulseIncrement);
                                                            ^
ANother_one:49:18: error: expected ';' before 'myPulsetime'
         m1.write myPulsetime = (mypulseTime + pulseIncrement)
                  ^
ANother_one:50:17: error: invalid use of non-static member function
         delay(1);
                 ^
exit status 1
expected ';' before 'myPulsetime'




UKHeliBob

Code: [Select]
    m1.write myPulsetime = (mypulseTime + pulseIncrement);
What are you trying to write to the servo ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Matyk

Servos and ESCs get the same kind of signal, 50Hz signal. The pulse signal varies from 1ms to 2ms, with 1ms represents the motor off completely and 2ms is the maximum speed and anything between is also varying speed.
so technically what I am trying to do is, for the first press of the button the signal would be 1500 (1250+250) so middle speed, second press it would be 1750 (1500+250) 3/4 of the max speed and for the third click, it would be 2000 (1750+250).

Go Up