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