Advertisement
alseambusher

Untitled

Sep 21st, 2024 (edited)
735
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. int split(String str, String *strs, char delimiter = ' ')
  2. {
  3.     int count = 0;
  4.     while (str.length() > 0)
  5.     {
  6.         int index = str.indexOf(delimiter);
  7.         if (index == -1)
  8.         {
  9.             strs[count++] = str;
  10.             break;
  11.         }
  12.         else
  13.         {
  14.             String out = str.substring(0, index);
  15.             out.replace("\n", "");
  16.             strs[count++] = out;
  17.             str = str.substring(index + 1);
  18.         }
  19.     }
  20.     return count;
  21. }
  22.  
  23.  
  24. void loop()
  25. {
  26.     while (!Serial.available())
  27.         ;
  28.    
  29.     auto message = Serial.readStringUntil('#');
  30.     String parsed[3];
  31.     auto count = split(message, parsed);
  32.     Log.notice("comms : %s %d" CR, message.c_str(), count);
  33.  
  34.     if (count == 3)
  35.     {
  36.         if (parsed[0] == "pan")
  37.         {
  38.  
  39.             pnts[parsed[1].toInt()].pan(parsed[2].toInt());
  40.         }
  41.         if (parsed[0] == "tilt")
  42.         {
  43.             pnts[parsed[1].toInt()].tilt(parsed[2].toInt());
  44.         }
  45.     } else if (count == 2)
  46.     {
  47.         if (parsed[0] == "led") {
  48.            kakashi::led::displayImage(kakashi::led::SHARINGAN[parsed[1].toInt()]);
  49.         }
  50.     }
  51.    
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement