//Parameters const int micPin = 2; unsigned long timeNow; unsigned long timeBefore; //Variables int micVal = 0; void setup() { //Init Serial USB Serial.begin(115200); Serial1.begin(115200); Serial.println(F("Initialize System")); //Init Microphone pinMode(micPin, INPUT); } void loop() { readMicrophone(); } void readMicrophone( ) { /* function readMicrophone */ ////Test routine for Microphone micVal = analogRead(micPin); Serial.print(F("mic val ")); Serial.println(micVal); int count = 0; if (micVal > 400) { timeBefore = timeNow; timeNow = millis(); int delta = timeNow-timeBefore; if ((count%2) == 0 && delta > 1000) { Serial1.println("turn0"); } if ((count%2) == 1 && delta > 1000) { Serial1.println("turn1"); } count += 1; } }