In my project I'm using the signal generator AD9833 with the library MD_AD9833. I'm struggling with generating an object to use AD9833.
There is an example code in the library
#include <MD_AD9833.h>
#include <SPI.h>
// Pins for SPI comm with the AD9833 IC
const uint8_t PIN_DATA = 11; ///< SPI Data pin number
const uint8_t PIN_CLK = 13; ///< SPI Clock pin number
const uint8_t PIN_FSYNC = 10; ///< SPI Load pin number (FSYNC in AD9833 usage)
MD_AD9833 AD(PIN_FSYNC); // Hardware SPI
void setup(void)
{...
In this example the object AD is generated at the beginning of the sketch where also variables are generated. In my object I have a header file DeviceClasses.h with following (reduced) content:
I inserted the line before the last one as a test only, to show that the compiler accepts to generate a pointer to an object MD_AD9833.
On the last line (same method as in the example program) the compiler generates error messages like
include/DeviceClasses.h:11:20: error: expected identifier before '(' token
#define CS_AD9833 (11)
^
include/DeviceClasses.h:92:16: note: in expansion of macro 'CS_AD9833'
MD_AD9833 AD(CS_AD9833);
^~~~~~~~~
include/DeviceClasses.h:11:21: error: expected ')' before numeric constant
#define CS_AD9833 (11)
^
include/DeviceClasses.h:92:16: note: in expansion of macro 'CS_AD9833'
MD_AD9833 AD(CS_AD9833);
^~~~~~~~~
and a lot more
The #define seems to be a problem and also the generation of the instance AD of MD_AD9833.
A better way to initialize might be dependency injection. Create an ad9833 object outside the funcgen class and pass it as parameter in the constructor or so.
2. What kind of waveform do you want to generate using the AD9833 chip? 3. Run the MD_AD9833_Basic.ino sketch from the Library and check that you are getting the expected waveform.
4. Study the sketch of Step-3 and learn the methodology of developing program using C++.
Unlike with one: inside a class/struct, two looks like you're declaring a function that returns a String and takes an integer. You certainly don't need to name your arguments, but you need the types; and the compiler -- for some reason -- allows you to "give an example" in this case.
With three and THREE, it's the same error, but with the macro confusing matters.
The fix is to use brace initialization, available since C++11, as shown with four. Do that consistently with all your object instantiation.