Skizze, die auf bestimmte Befehle reagiert, wie geht das?

Okay, ich habe im Moment eine halbfertige Arduino-Skizze. Grundsätzlich blinkt in der folgenden Skizze eine LED auf einem Kegboard-Mini-Schild, wenn eine Zeichenfolge gleich * {blink_Flow_A} * ist. Die LED blinkt jedoch nur einmal, wenn die aktuelle Skizze auf dem Arduino geladen ist. Ich möchte, dass der Arduino wiederholt blinkt, bis der "Stopp" -Befehl an den Arduino gesendet wird. Ich möchte irgendwann ein Ventil öffnen, es offen halten, bis das Ventil den Befehl zum Schließen erhält, und dann das Ventil schließen. Die Skizze sieht folgendermaßen aus:

/*
 * kegboard-serial-simple-blink07
 * This code is public domain
 *
 * This sketch sends a receives a multibyte String from the iPhone
 * and performs functions on it.
 *
 * Examples:
 * http://arduino.cc/en/Tutorial/SerialEvent
 * http://arduino.cc/en/Serial/read
 */

 // global variables should be identified with _

 // flow_A LED
 int led = 4;

 // relay_A
 const int RELAY_A = A0;

 // variables from sketch example
 String inputString = ""; // a string to hold incoming data
 boolean stringComplete = false; // whether the string is complete

 void setup() {

   Serial.begin(2400); // open serial port, sets data rate to 2400bps
   Serial.println("Power on test");
   inputString.reserve(200);

   pinMode(RELAY_A, OUTPUT);
}

void open_valve() {

  digitalWrite(RELAY_A, HIGH); // turn RELAY_A on

}

void close_valve() {

  digitalWrite(RELAY_A, LOW); // turn RELAY_A off
}

void flow_A_blink() {

  digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
  delay(1000);              // wait for one second
  digitalWrite(led, LOW);   // turn the LED off by making the voltage LOW
  delay(1000);              // wait for a second
}

void flow_A_blink_stop() {

  digitalWrite(led, LOW);
}

void loop() {
  // print the string when newline arrives:
  if (stringComplete) {
    Serial.println(inputString);
    // clear the string:
    inputString = "";
    stringComplete = false;
  }

  if (inputString == "{blink_Flow_A}") {
    flow_A_blink();
  }
}

//SerialEvent occurs whenever a new data comes in the
//hardware serial RX.  This routine is run between each
//time loop() runs, so using delay inside loop can delay
//response.  Multiple bytes of data may be available.

void serialEvent() {
  while(Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
}

Wenn es einen Unterschied macht, hat mich jemand im IRC angewiesen, nach Zustandsautomaten zu suchenKratzer am Kopf

Antworten auf die Frage(4)

Ihre Antwort auf die Frage