Advertisement
Guest User

Untitled

a guest
Feb 1st, 2025
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #include "sbus.h"
  2.  
  3. #define THR_CH 2
  4. #define ARM_CH 4
  5. #define ANGLE_CH 6
  6.  
  7. #define ANGLE_ENABLE 1000
  8. #define ARM_ENABLE 1900
  9. #define ARM_DISABLE 1000
  10.  
  11.  
  12. bfs::SbusTx sbus_tx(&Serial1, 6, 7, true, false);
  13. bfs::SbusData data;
  14. int counter = 0;
  15.  
  16. int drone_to_sbus(int k) {
  17. return (k - 880) * 8 / 5;
  18. }
  19.  
  20. void setup() {
  21. Serial.begin(115200);
  22. // Serial1.begin(115200, SERIAL_8N1, 6, 7);
  23.  
  24. sbus_tx.Begin();
  25.  
  26. data.failsafe = false;
  27. data.ch17 = true;
  28. data.ch18 = true;
  29. data.lost_frame = false;
  30.  
  31. delay(1000);
  32. Serial.println("setup finished ESP-C3-Zero");
  33. }
  34.  
  35.  
  36. void loop() {
  37. counter += 1;
  38. delay(20);
  39.  
  40. if (counter > 1500) {
  41. return;
  42. }
  43.  
  44. data.failsafe = (counter >= 350);
  45.  
  46. for (int j = 0; j < 16; j++) {
  47. data.ch[j] = 992;
  48. }
  49. data.ch[THR_CH] = drone_to_sbus(1150);
  50. data.ch[ARM_CH] = drone_to_sbus(ARM_ENABLE);
  51. data.ch[ANGLE_CH] = drone_to_sbus(ANGLE_ENABLE);
  52. sbus_tx.data(data);
  53. sbus_tx.Write();
  54.  
  55. Serial.printf("%d: sent ch0=%d\n", counter, data.ch[0]);
  56.  
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement