const int LED_PIN = 9;
const int BUTTON_RECORD = 2;
const int BUTTON_PLAY = 3;
const int BUTTON_RESET = 4;
String morseCode = "";
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(BUTTON_RECORD, INPUT_PULLUP);
pinMode(BUTTON_PLAY, INPUT_PULLUP);
pinMode(BUTTON_RESET, INPUT_PULLUP);
}
void loop() {
if (digitalRead(BUTTON_RECORD) == LOW) {
morseCode += ".";
digitalWrite(LED_PIN, HIGH);
delay(200);
digitalWrite(LED_PIN, LOW);
delay(200);
}
if (digitalRead(BUTTON_PLAY) == LOW) {
playMorse(morseCode);
}
if (digitalRead(BUTTON_RESET) == LOW) {
morseCode = "";
}
}
void playMorse(String code) {
for (char c : code) {
if (c == '.') {
digitalWrite(LED_PIN, HIGH);
delay(200);
digitalWrite(LED_PIN, LOW);
delay(200);
}
delay(600);
}
}
Дано: 1 светодиод, 1 резистор номиналом 220 Ом и 3 резистора номиналом 10 кОм, 3 кнопки, провода, контроллер.