Pulse the motor without delay()
Arduino C++Switch the motor on for 1 s and off for 1 s, forever, using millis() instead of delay(), so the sketch could still read buttons or sensors in between.
Checks
- Not run yetPin 9 toggles with a 2 s period
- Not run yetThe motor is on at 1.5 s
- Not run yetThe motor is off at 2.5 s
- Not run yetUses millis(), no delay()
Hints
- Remember when you last switched: unsigned long last = 0;
- In loop(), when millis() - last >= 1000, add 1000 to last and flip the pin.
- digitalWrite(MOTOR, on ? HIGH : LOW) writes a bool flag to the pin.