DShotRMT/examples/dshot300/dshot300.ino

44 lines
963 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
DShotRMT dshot_01(GPIO_NUM_4, RMT_CHANNEL_0);
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
void setup() {
// ...always start the onboard usb support
USB_Serial.begin(USB_SERIAL_BAUD);
// ...start the dshot generation
dshot_01.begin(DSHOT300);
}
void loop() {
2021-06-30 05:43:07 +01:00
read_SerialThrottle();
2021-06-30 02:06:02 +01:00
dshot_01.send_dshot_value(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
}
//
//
2021-06-30 05:43:07 +01:00
uint16_t read_SerialThrottle() {
2021-06-30 02:06:02 +01:00
if (USB_Serial.available() > 0) {
auto throttle_input = (USB_Serial.readStringUntil('\n')).toInt();
2021-06-30 05:43:07 +01:00
return throttle_input;
} else {
return FAILSAVE_THROTTLE;
}
2021-06-30 02:06:02 +01:00
}