Softata: Arduino Issues
January 15, 2024 21:53
David Jones MVP
softata
rpipico
firmata
arduino
csharp
bme280
grove
pico
sdk-for-c-arduino
tcpip
15 Jan 2024 21:53:33
David Jones MVP
softata rpipico firmata arduino csharp bme280 grove pico sdk-for-c-arduino tcpip
softata rpipico firmata arduino csharp bme280 grove pico sdk-for-c-arduino tcpip
Some Arduino workarounds.
One issue when using an existing Arduino library to implement a device, is where the instance declaration requires a parameter such as a pin. This can be an issue where, for example, the pin is only known at runtime. The workaround is to declare it as a pointer then when it is to instantiated at runtime, it is created with a new() call with the parameter as an argument. For example, the Grove Ultrasonic Ranger:
Sample code typically will define it thus
#define PIN 7
Ultransonic ultrasonic(PIN);
The pointer approach is:
Ultrasonic * ultrasonic;
void Setup(int SetupPin)
{
ultrasonic = new Ultrasonic(SetupPin);
}
Then change code such as
ultrasonic.MeasureInMillimeters()
to
ultrasonic->MeasureInMillimeters()
Topic | Subtopic | |
This Category Links | ||
Category: | Softata Index: | Softata |
Next: > | Softata | Grove Actuator Class API |
< Prev: | Softata | Grove Display Class API |