Differences
This shows you the differences between two versions of the page.
— |
de:project:blink_with_millis [2022/04/21 15:01] () |
||
---|---|---|---|
1: | 1: | ||
+ | ===== LED-Blinken mit der Funktion " | ||
+ | Blinken der LED am " | ||
+ | |||
+ | * pause_time = 100; : waiting time: 0.1 sec | ||
+ | * after //%%//%% switch// : timer-related operations can be inserted here | ||
+ | |||
+ | <code c> | ||
+ | // source: ob121.com - Vamos Sandor 2018 | ||
+ | |||
+ | float current_time, | ||
+ | bool blink_on; | ||
+ | |||
+ | void setup() { | ||
+ | pinMode(13, OUTPUT); | ||
+ | current_time = millis(); | ||
+ | old_time = current_time; | ||
+ | pause_time = 100; // pause (waiting) time, in here 0,1 sec | ||
+ | } | ||
+ | |||
+ | // the loop function runs over and over again forever | ||
+ | void loop() { | ||
+ | |||
+ | // ----------------------- timer | ||
+ | |||
+ | current_time = millis(); | ||
+ | | ||
+ | if (current_time < old_time) { // after overflow | ||
+ | old_time = current_time; | ||
+ | } | ||
+ | if ((current_time - old_time) > pause_time) { // time is gone | ||
+ | old_time = current_time; | ||
+ | |||
+ | // switch | ||
+ | blink_on = !blink_on; | ||
+ | } | ||
+ | |||
+ | // ------------------------ blink | ||
+ | if (blink_on) { | ||
+ | digitalWrite(13, | ||
+ | } else { | ||
+ | digitalWrite(13, | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </ | ||
+ | |||
+ | **[[de: |