MThardPWM: Example 2
Event management for Uno, Nano, Mega
Flashing of an LED
This program will make LED_BUILTIN flash
We will use the Hard PWM to be a succession of flashes. A double metronome will turn on and turn off these flashes. It is the PWM which will therefore make the flashes and the double metronome that will generally give the flashing. On a mega, LED_BUILTIN corresponds to a pin accepting this hard PWM, there is nothing more to do. On a Uno/Nano, the LED_BUILTIN pin does not accept it, you can use output 9 to make the PWM and put a stew wire between pin 9 and pin 13. If you say nothing, pin 13 will be at the INPUT state which is perfect.

or:

or:

Complete program recommended
This program is completely under interruption, and releases loop which can be used to do something else.
// This program will make LED_BUILTIN flash. You need a wire between pin 9 and // 13 for a Uno/Nano #include <MTobjects.h> // V1.0.6 See http://arduino.dansetrad.fr/en/MTobjects // Implementation of flashes // On Uno/Nano the usable pins are: 9, 10. wHere we have to put a wire between pin 9 and pin 13 MThardPWM FiveFlash(9, inpulses_width 50000 micro_seconds, periods_width 100000 micro_seconds); // On Mega the usable pins are: 2, 3, 5, 6, 7, 8, 11, 12, 13, 44, 45, 46 //MThardPWM FiveFlash(13, inpulses_width 50000 micro_seconds, periods_width 100000 micro_seconds); // Global blinking void startBlinking(void) // Start the flashs { FiveFlash.attach(); } void stopBlinking(void) // Stop the flashs { FiveFlash.detach(); pinMode(9, OUTPUT); // After a detach, the pinis in INPUT state, and the BUITLIN_LED lights up then } MTdoubleClock Metronome(500 milli_seconds, 1000 milli_seconds, stopBlinking, startBlinking); void setup(){} void loop(){}