| 16 | {{{!#c |
| 17 | #define MAXTIMER 16 |
| 18 | long waitForTimer[MAXTIMER]; |
| 19 | int waitFor(int timer, long period){ |
| 20 | long newTime = micros() / period; |
| 21 | int delta = newTime - waitForTimer[timer]; |
| 22 | if ( delta ) { |
| 23 | waitForTimer[timer] = newTime; |
| 24 | } |
| 25 | return delta; |
| 26 | } |
| 27 | |
| 28 | void setup() { |
| 29 | pinMode(13,OUTPUT); |
| 30 | Serial.begin(115200); |
| 31 | } |
| 32 | |
| 33 | void Led(int timer, long period, int led) { |
| 34 | static int val = 0; |
| 35 | if (!waitFor(timer,period)) return; |
| 36 | digitalWrite(13,val); |
| 37 | val = 1 - val; |
| 38 | } |
| 39 | |
| 40 | void Mess(int timer, long period, const char * mess) { |
| 41 | if (!waitFor(timer,period)) return; |
| 42 | Serial.println(mess); |
| 43 | } |
| 44 | |
| 45 | void loop() { |
| 46 | Led (0,100000,13); |
| 47 | Mess(1,1000000,"bonjour"); |
| 48 | } |
| 49 | }}} |