// function to change speed
newSpeed (stepSpeed1, stepSpeed2)
{
stepper1.setSpeed(stepSpeed1);
stepper2.setSpeed(stepSpeed2);
}
```
If this is a plain C function, it needs a return type... if that is the whole function, it probably needs to be
void newSpeed (stepSpeed1, stepSpeed2) { stepper1.setSpeed(stepSpeed1); stepper2.setSpeed(stepSpeed2); }
If it is a c++ member function it must also have class name in front of it...
void yourClass::newSpeed (stepSpeed1, stepSpeed2) { stepper1.setSpeed(stepSpeed1); stepper2.setSpeed(stepSpeed2); }
3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide
Please read the Help about how to post code. Also, do a screen grab ot copy paste of the actual errors, do NOT try to type it in yourself. Sometimes it helps to scroll back thru the output listing to see if there is any more lines in RED. Of course you have set prefs to Compiler Warnings ALL.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.
I copied the code with "Copy for Forum" and pasted it into the text field. I simply copied and pasted the error message and manually highlighted it. I am using Arduino 2.0.0-9.4 where "Copy for Forum" is only accessed from the edit menu. Am I doing something wrong?
@inq I copied your plain C code and got this error. Compilation error: variable or field 'newSpeed' declared void
Removing "void" gave this error: "Compilation error: expected constructor, destructor, or type conversion before '(' token"
I didn't try the C++ because I don't understand theC++ class system.
When I remove the function, all code compiles OK.
I didn't have a problem with functions that have no return value.
@barrie It's confusing, but for the forum it's better to use the other option 'Copy as HTML' you can see an example of that in the preceding post https://forum.dronebotworkshop.com/postid/33743 /" target="_blank" rel="noopener"> https://forum.dronebotworkshop.com/postid/33743/
I think that post also has the answer to your query.
I tried that code snippet and was greeted with the following
ketch_sep14a:10:10: error: expected constructor, destructor, or type conversion before '(' token
newSpeed (stepSpeed1, stepSpeed2)
^
sketch_sep14a:10:10: error: expected constructor, destructor, or type conversion before '(' token
newSpeed (stepSpeed1, stepSpeed2)
^
exit status 1
expected constructor, destructor, or type conversion before '(' token
Notice the ^ missing in yours.
It's not enough info to just copy the one line, the surrounding lines are generally more informative.
@Inq has translated the error message into the actual form required. However uncharacteristically he missed a couple other errors, namely the types for the two stepSpeedx variables and the declaration for stepper1 and stepper2.
I am not C++ savvy, so I might have overlooked something, but I think we got it all.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.
@barrie - @zander is right, I missed more obvious things.
- All functions MUST have return types. If you don't want to return something to the calling code, you must prefix it with void.
- All parameters must have a variable type. As the stepper.h library functions void setSpeed(long whatSpeed); use a long, you need to pass in that long...
void newSpeed (long stepSpeed1, long stepSpeed2) { stepper1.setSpeed(stepSpeed1); stepper2.setSpeed(stepSpeed2); }
3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide
Oh dear! version 2.0 does not have 'Copy as HTML'. I Sorry, I don't understand the relevance of '^'.
I will try to post the entire code using version 1.8.19.
Oh dear! version 2.0 does not have 'Copy as HTML'. I Sorry, I don't understand the relevance of '^'.
I will try to post the entire code using version 1.8.19.
No, you don't need to do that.
Simply highlight all the text you want to include from whatever editor 2.0, 1.8.19, any other editor. I use Notepad++ for instance.
In this forum's editor, simply click the <> button where you want to add source code.
Paste it in the popup window... Done.
3 lines of code = InqPortal = Complete IoT, App, Web Server w/ GUI Admin Client, WiFi Manager, Drag & Drop File Manager, OTA, Performance Metrics, Web Socket Comms, Easy App API, All running on ESP8266...
Even usable on ESP-01S - Quickest Start Guide
@inq Also missing declares for stepper1 and stepper2 but they may be in the global section
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.
@inq I declared the stepspeed variables as integers in the spaces above Void setup(). I changed them to long but still got error. I will post all the code and hopefully you will find it easier to spot my error.
@barrie You have to also specify the type for the parameters as in
void newSpeed(long stepSpeed1, long stepSpeed2)
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.
Should this have the keywords highlighted?
@barrie You did not follow the instructions, here they are
Step 1 – Copy the code sample from your computers editor, it can be any text editor or IDE.
Step 2 – Paste it into your post, at the point you want the sample to occur
Step 3 – To make things easier add a couple of line feeds after you paste it.
Step 4 – Highlight the code in your post.
Step 5 – Click the Code button (the one that looks like “<>”) on the post editor toolbar.
First computer 1959. Retired from my own computer company 2004.
Hardware - Expert in 1401, and 360, fairly knowledge in PC plus numerous MPU's and MCU's
Major Languages - Machine language, 360 Macro Assembler, Intel Assembler, PL/I and PL1, Pascal, Basic, C plus numerous job control and scripting languages.
Sure you can learn to be a programmer, it will take the same amount of time for me to learn to be a Doctor.