Advertisement
Guest User

Untitled

a guest
Dec 10th, 2016
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. #include "Arduino.h"
  2. #include "config.h"
  3.  
  4.  
  5.  
  6. struct TTEST {
  7. char id[3];
  8. bool test_bool;
  9. uint8_t ipadress[4];
  10. uint8_t volume;
  11. uint16_t freq;
  12. bool test_bool2;
  13. uint16_t count;
  14. uint32_t u32test;
  15. float flfoo;
  16. int testint;
  17. } struct_data = {
  18. "01",
  19. true,
  20. { 10, 9, 5, 241 },
  21. 22,
  22. 1234,
  23. false,
  24. 6699,
  25. 568902,
  26. 1337.337,
  27. -55
  28. };
  29.  
  30.  
  31. void send_struct(){
  32. char b[sizeof(struct_data)];
  33. memcpy(b, &struct_data, sizeof(struct_data));
  34. Serial.write(sizeof(struct_data));
  35. delay(10);
  36. for (int i=0; i<(sizeof(b)+1); i++){
  37. Serial.write(b[i]);
  38. }
  39. }
  40.  
  41.  
  42. void setup() {
  43. Serial.begin(SERIAL_BAUD);
  44. }
  45.  
  46. uint8_t serial_command;
  47.  
  48. void loop() {
  49. if (Serial.available()) {
  50. serial_command = Serial.read();
  51. switch (serial_command) {
  52.  
  53. // on
  54. case 4:
  55. send_struct();
  56. break;
  57.  
  58. }
  59. }
  60. delay(1);
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement