// on_off_time at 10 ms to speed up the time // on_off_time at 7/8 ms to speed up the time backwards // Open the serial to specify the on-off_time in ms // Close and reopen to insert a new one int on_off_time = 1000; void setup() { Serial.begin(9600); pinMode(9, OUTPUT); pinMode(10, OUTPUT); } void loop() { // // DEBUG with Serial Monitor // // if (Serial.available() > 0) { // check if there's any incoming serial data // int new_delay = Serial.parseInt(); // read the incoming integer value // if (new_delay >= 0 && new_delay <= 1023) { // check if the value is within range // on_off_time = new_delay; // set the new threshold value // Serial.end(); // } // } // digitalWrite(10, HIGH); // digitalWrite(9, LOW); // delay(on_off_time); // digitalWrite(10, LOW); // digitalWrite(9, HIGH); // delay(on_off_time); // ///////////////////////////////// if (Serial.available() >= 1) { byte data[1]; Serial.readBytes(data, 1); // 1 bytes are send by the python script each second int firstBit = (data[0] & 0b00000001); // extract the first bit and shift it to the rightmost position if (firstBit == 1) { digitalWrite(10, HIGH); digitalWrite(9, LOW); delay(on_off_time); digitalWrite(10, LOW); digitalWrite(9, HIGH); delay(on_off_time); } else { // do something if the first bit is 0 } } }