chip_x
December 15, 2019, 12:56pm
1
Hello everyone, I wrote a function that serves to set the pins of the DRV8825 respectively m0,m1,m2.
But one thing happens that I don't know how to solve: if I insert the function does not work if I insert the 3 lines of code, extracted from the function, it works. it seems a pun. I attach files.
I can't get there... Will I be a donkey? hi hó hi hó
Thank you.
chip
function
void micro1_32(void){
digitalWrite(M0,HIGH);
digitalWrite(M1,HIGH);
digitalWrite(M2,HIGH);
}
test1.ino (599 Bytes)
Microstepping.h (85 Bytes)
Microstepping.cpp (133 Bytes)
That's how it works!.ino (680 Bytes)
In test1.ino this line of code
void micro1_32(void);
is not calling the function, rather it is a function prototype
Note how that line of code differs from the next one
digitalWrite(Dir,HIGH);
Spot the difference
system
December 15, 2019, 1:14pm
3
how are M0, M1 and M2 defined (known) in Microstepping.cpp? those constants (#defs ) are only defined in test1.ino. I would have expected an error
you can try defining all the constants in Microstepping.h since it's included in both the .ino and .cpp
chip_x
December 15, 2019, 2:05pm
4
For UKHeliBob, then it is probably not a function but a procedure. If so, why shouldn't it do it?
For gciurpita, I attached the .h and .cpp files so you can see how I defined them.
then it is probably not a function but a procedure
In C++, which the Arduino uses, there is no such thing as a procedure. If a function does not accept or return values then it is still a function
Try this
void setup()
{
Serial.begin(115200);
void function1(); //tell the compiler that function1 exists
function2(); //call function2
}
void loop()
{
}
void function1(void)
{
Serial.println("in function1");
}
void function2(void)
{
Serial.println("in function2");
}
Now substitute this setup() function and try again
void setup()
{
Serial.begin(115200);
function1(); //call function1
function2(); //call function2
}
chip_x
December 16, 2019, 7:37pm
6
Thank you! I've tried it and that's how it works. I also managed to produce a .h file and a .cpp file. I didn't remember a few things...
chip