DShotRMT/examples/dshot300/dshot300.ino

47 lines
872 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()
{
2022-11-26 12:52:46 +00:00
// ...always start the onboard usb support
USB_Serial.begin(USB_SERIAL_BAUD);
2021-06-30 02:06:02 +01:00
}
2022-11-25 15:08:58 +00:00
void loop()
{
2022-11-26 12:52:46 +00:00
read_SerialThrottle();
2021-06-30 05:43:07 +01:00
motor01.send_dshot_value(throttle_value);
2021-06-30 05:43:07 +01:00
2022-11-26 12:52:46 +00:00
// ...print to console
USB_Serial.println(throttle_value);
2021-06-30 02:06:02 +01:00
}
//
//
2022-11-25 15:08:58 +00:00
uint16_t read_SerialThrottle()
{
2022-11-26 12:52:46 +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
}