2 add more general case edited Sep 4 '16 at 22:44 James Waldby - jwpat7 8,02733 gold badges1010 silver badges2929 bronze badges Consider code of the following form. ``````// Declare some globals byte direction=0, second, prev=0; void loop() { second = millis()/1000; if (prev != second) { prev = second; direction = second & 1; // Direction is 0 or 1 OutputTheNewDirection(direction); } `````` More generally, suppose you want to make a pattern of clockwise for j time units, alternating with counterclockwise for k time units. Suppose a time unit is m milliseconds long. You can use code as in the following example, where m is 500, j is 10, and k is 1. ``````// Declare some globals and constants byte direction=0, tunit, prev=0; enum { m=500, j=10, k=1 }; void loop() { tunit = (millis()/m) % (j+k); if (prev != tunit) { prev = tunit; direction = tunit < j; // Direction is 0 or 1 OutputTheNewDirection(direction); } `````` Consider code of the following form. ``````// Declare some globals byte direction=0, second, prev=0; void loop() { second = millis()/1000; if (prev != second) { prev = second; direction = second & 1; // Direction is 0 or 1 OutputTheNewDirection(direction); } `````` Consider code of the following form. ``````// Declare some globals byte direction=0, second, prev=0; void loop() { second = millis()/1000; if (prev != second) { prev = second; direction = second & 1; // Direction is 0 or 1 OutputTheNewDirection(direction); } `````` More generally, suppose you want to make a pattern of clockwise for j time units, alternating with counterclockwise for k time units. Suppose a time unit is m milliseconds long. You can use code as in the following example, where m is 500, j is 10, and k is 1. ``````// Declare some globals and constants byte direction=0, tunit, prev=0; enum { m=500, j=10, k=1 }; void loop() { tunit = (millis()/m) % (j+k); if (prev != tunit) { prev = tunit; direction = tunit < j; // Direction is 0 or 1 OutputTheNewDirection(direction); } `````` 1 answered Sep 4 '16 at 18:28 James Waldby - jwpat7 8,02733 gold badges1010 silver badges2929 bronze badges Consider code of the following form. ``````// Declare some globals byte direction=0, second, prev=0; void loop() { second = millis()/1000; if (prev != second) { prev = second; direction = second & 1; // Direction is 0 or 1 OutputTheNewDirection(direction); } ``````