Go Down

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

#### UKHeliBob

#15
##### Mar 22, 2019, 11:23 am
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 amLast 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

#17
##### Mar 22, 2019, 11:42 am
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

#18
##### Mar 22, 2019, 11:44 am
it is 15 milliseconds, if the ESC gets 1500 it does not output any speed, 1500- 2000 is the actual speed

#### Matyk

#19
##### Mar 22, 2019, 11:54 am
and do you know how I could solve the: two or more data types in declaration of 'buttonPin'

#### Matyk

#20
##### Mar 22, 2019, 12:00 pm
// 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() {

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

#21
##### Mar 22, 2019, 12:08 pm
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

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

#### johnwasser

#23
##### Mar 22, 2019, 12:42 pm
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

#24
##### Mar 22, 2019, 01:19 pm
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

#25
##### Mar 22, 2019, 01:24 pm
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() {

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

#26
##### Mar 22, 2019, 02:08 pm
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 pmLast 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() {

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"

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

#28
##### Mar 22, 2019, 09:44 pm
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

#29
##### Mar 22, 2019, 09:54 pm
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