DShotRMT/examples/dshot300/dshot300.ino

50 lines
992 B
Arduino
Raw Normal View History

2021-06-30 02:06:02 +01:00
// ...some very simple DShot example generating a DShot300 signal.
#include <Arduino.h>
2021-07-26 21:20:49 +01:00
#include <DShotRMT.h>
2021-06-30 02:06:02 +01:00
// ...clearly name usb port
#ifdef SERIAL
#define USB_Serial Serial
constexpr auto USB_SERIAL_BAUD = 115200;
#endif // SERIAL
2023-03-26 16:58:24 +01:00
DShotRMT motor01(GPIO_NUM_4, RMT_CHANNEL_0);
2021-06-30 02:06:02 +01:00
volatile uint16_t throttle_value = 0x30; // ...sending "48", the first throttle value
2021-06-30 05:43:07 +01:00
constexpr auto FAILSAVE_THROTTLE = 0x3E7;
2021-06-30 02:06:02 +01:00
2022-11-25 15:08:58 +00:00
void setup()
{
// ...always start the onboard usb support
USB_Serial.begin(USB_SERIAL_BAUD);
// ...start the dshot generation
motor01.begin(DSHOT300);
2021-06-30 02:06:02 +01:00
}
2022-11-25 15:08:58 +00:00
void loop()
{
readSerialThrottle();
2021-06-30 05:43:07 +01:00
motor01.sendThrottleValue(throttle_value);
2021-06-30 05:43:07 +01:00
// ...print to console
USB_Serial.println(throttle_value);
2021-06-30 02:06:02 +01:00
}
//
//
uint16_t readSerialThrottle()
2022-11-25 15:08:58 +00:00
{
if (USB_Serial.available() > 0)
{
auto throttle_input = (USB_Serial.readStringUntil('\n')).toInt();
return throttle_input;
}
else
{
return FAILSAVE_THROTTLE;
}
2021-06-30 02:06:02 +01:00
}