Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. float btof(byte * payload, unsigned int length) {
  2.  
  3. char * demo = (char *) malloc(sizeof(char) * 10);
  4.  
  5. for (int i = 0; i < length; i++) {
  6.  
  7. demo[i] = payload[i];
  8.  
  9. }
  10.  
  11. float value = atof(demo);
  12.  
  13. free(demo);
  14.  
  15. return value;
  16. }
  17.  
  18. // Callback to handle subscription
  19.  
  20. void callback(char* topic, byte* payload, unsigned int length)
  21.  
  22. {
  23.  
  24. value = btof(payload, length);
  25.  
  26. value = map(value, 0, 1023, 0, 180);
  27.  
  28. //Map the 0-100 values from the slider to the 0-180 to use the servo lib.
  29.  
  30. ESC.write(value);
  31.  
  32. //Send the value (PWM) to the ESC
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement