总是在关注Arduino / Raspberry Pi

时间:2013-06-17 16:07:09

标签: arduino keyword listen siri

我想让Siri像贾维斯一样。我将使用Mindstorm按下主页按钮。我需要Arduino / Raspberry Pi来听取像Siri这样的关键词来控制Mindstorm。如果您有代码或建议,请给出答案。 感谢

1 个答案:

答案 0 :(得分:1)

如果您需要Arduino在RPi与之对话时采取行动,您可以使用类似的东西。

// Buffer to store incoming commands from serial port
String inData;

void setup() {
    Serial.begin(9600);
    Serial.println("Serial conection started, waiting for instructions...");
}

void loop() {
    while (Serial.available() > 0)
    {
        char recieved = Serial.read();
        inData += recieved; 

        // Process message when new line character is recieved
        if (recieved == '\n')
        {
            Serial.print("Arduino Received: ");
            Serial.print(inData);

            // You can put some if and else here to process the message juste like that:

            if(inData == "Siri\n"){ // DON'T forget to add "\n" at the end of the string.
              Serial.println("What can I do for you?");
            }


            inData = ""; // Clear recieved buffer
        }
    }
}