blink example

This commit is contained in:
Alexander Popov 2023-02-24 19:38:04 +03:00
commit b12135c779
Signed by: iiiypuk
GPG Key ID: D8C9B59A9F04A70C
3 changed files with 69 additions and 0 deletions

16
.editorconfig Normal file
View File

@ -0,0 +1,16 @@
root = true
[*]
indent_style = space
indent_size = 4
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[{*.c,*.ino,*.h}]
indent_style = space
indent_size = 2
[*.md]
trim_trailing_whitespace = false

View File

@ -0,0 +1,40 @@
/*
Blink BUILTIN LED example
Author: Alexander Popov
License: Unlicense
*/
#include "start.h"
/* Blink method:
true -- delay() used
false -- millis() used */
bool blink_method = true;
bool led_state = HIGH;
unsigned long timer = 0;
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
init_blink(5, 70);
}
void loop() {
// blink_method = true
if (blink_method == true) {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
// blink_method = false
else {
if (millis() - timer > 200) {
led_state =! led_state;
digitalWrite(LED_BUILTIN, led_state);
timer = millis();
}
}
}

View File

@ -0,0 +1,13 @@
/*
Author: Alexander Popov
License: Unlicense
*/
void init_blink(int times, int delay_time) {
for (int count = 0; count < times; count++) {
digitalWrite(LED_BUILTIN, HIGH);
delay(delay_time);
digitalWrite(LED_BUILTIN, LOW);
delay(delay_time);
}
}