SHARE
TWEET

Untitled

a guest May 25th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. String inputString;
  2.  
  3. void setup()
  4. {
  5.   Serial.begin(9600);
  6. }
  7.  
  8. void loop() {
  9.   if (Serial.available() > 8)
  10.   {
  11.     {
  12.  
  13.       inputString = Serial.readStringUntil('\n');
  14.       char *check = inputString.charAt(0);
  15.       if (check == 'A')
  16.       {
  17.         char steering[4] = {'0', '0', '0', '\0' };            //Char ohjaus = uusi 3 kirjaimen array
  18.         char throttle[4] = {'0', '0', '0', '\0' };            //Char kaasu = uusi 3 kirjaimen array
  19.         char function[4] = {'0', '0', '0', '\0' };            //Char toiminto = uusi 3 kirjaimen array
  20.  
  21.         steering[0] = inputString.charAt(1);     //Array steering's first index = second character of inputString
  22.         steering[1] = inputString.charAt(2);     //Array steering's second index = third character of inputString
  23.         steering[2] = inputString.charAt(3);     //Array steering's third index = fourth character of inputString
  24.         throttle[0] = inputString.charAt(4);     //Array throttle's first index = fifth character of inputString
  25.         throttle[1] = inputString.charAt(5);     //Array throttle's second index = sixth character of inputString
  26.         throttle[2] = inputString.charAt(6);     //Array throttle's third index = seventh character of inputString
  27.         function[0] = inputString.charAt(7);     //Array function's first index = eight character of inputString
  28.         function[1] = inputString.charAt(8);     //Array function's second index = ninth character of inputString
  29.         function[2] = inputString.charAt(9);     //Array function's third index = tenth character of inputString
  30.  
  31.         int steeringVal = atoi(steering);        //Integer steeringVal = Char steering converted to integer
  32.         int throttleVal = atoi(throttle);        //Integer throttleVal = Char throttle converted to integer
  33.         int functionVal = atoi(function);        //Integer functionVal = Char function converted to integer
  34.  
  35.         Serial.print("ImputString:");
  36.         Serial.println(inputString); //tulostaa input msg arvon.
  37.  
  38.  
  39.  
  40.         ///////////////////////////////////////////////////////////////////////////
  41.         //    Serial.print("ImputString:");
  42.         //    Serial.println(inputString); //tulostaa input msg arvon.
  43.         //    Serial.print("CHAR_Steering:");
  44.         //    Serial.println(steering); //tulostaa input msg arvon.
  45.         //    Serial.print("CHAR_Throttle:");
  46.         //    Serial.println(throttle); //tulostaa input msg arvon.
  47.         //    Serial.print("CHAR_Function:");
  48.         //    Serial.println(function); //tulostaa input msg arvon.
  49.         //
  50.         //    Serial.print("Steering:");
  51.         //    Serial.println(steeringVal); //tulostaa input msg arvon.
  52.         //    Serial.print("Throttle:");
  53.         //    Serial.println(throttleVal); //tulostaa input msg arvon.
  54.         //    Serial.print("Function:");
  55.         //  Serial.println(functionVal); //tulostaa input msg arvon.
  56.         ///////////////////////////////////////////////////////////////////////////
  57.  
  58.  
  59.       }
  60.     }
  61.   }
  62. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top