blink example
This commit is contained in:
commit
b12135c779
16
.editorconfig
Normal file
16
.editorconfig
Normal 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
|
40
Difficulty 01/blink/blink.ino
Normal file
40
Difficulty 01/blink/blink.ino
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
13
Difficulty 01/blink/start.h
Normal file
13
Difficulty 01/blink/start.h
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user