2016-06-23 5 views
0

나는 Arduino Uno에 매우 익숙하며 약간의 조언이 필요합니다 .... 그래서 여기에 우리가 간다.arduino uno 문자열이 단어를 의미하면

내가 내 아두 이노를 사용하려면 :
1. 내 직렬 데이터는 데이터의 라인 내에서 일반 텍스트로받은 특정 단어에 대한
2. 모양을 --received 읽어
3 만 /를 인쇄 전송 이 특정 "단어"

이 포함 된 경우 전체 문자열은 내가이 스케치를 발견하고 내가 그것을 String 클래스의 방법을 사용하는 것이 좋습니다 생각 문자

// Example 3 - Receive with start- and end-markers 

const byte numChars = 32; 
char receivedChars[numChars]; 

boolean newData = false; 

void setup() { 
    Serial.begin(9600); 
    Serial.println("<Arduino is ready>"); 
} 

void loop() { 
    recvWithStartEndMarkers(); 
    showNewData(); 
} 

void recvWithStartEndMarkers() { 
    static boolean recvInProgress = false; 
    static byte ndx = 0; 
    char startMarker = '<'; 
    char endMarker = '>'; 
    char rc; 

    while (Serial.available() > 0 && newData == false) { 
     rc = Serial.read(); 

     if (recvInProgress == true) { 
      if (rc != endMarker) { 
       receivedChars[ndx] = rc; 
       ndx++; 
       if (ndx >= numChars) { 
        ndx = numChars - 1; 
       } 
      } 
      else { 
       receivedChars[ndx] = '\0'; // terminate the string 
       recvInProgress = false; 
       ndx = 0; 
       newData = true; 
      } 
     } 

     else if (rc == startMarker) { 
      recvInProgress = true; 
     } 
    } 
} 

void showNewData() { 
    if (newData == true) { 
     Serial.print("This just in ... "); 
     Serial.println(receivedChars); 
     newData = false; 
    } 
} 

답변