Morse project with function, paramtrers and switch
SOS code with 3 functions
Morse project with functions, parameters and switch
Sos code with 3 functions
SOS code with 3 functions
const byte ledPin = 13;
void setup() {
// Use ledPin as output
pinMode(ledPin, OUTPUT) ;
//Create a function for short blink
void shortBlink() {
// Make a single short blin
digitalWrite(ledPin, HIGH) ;
delay(200) ;
digitalWrite(ledPin, LOW) ;
delay(200) ;
void longBlink() {
// Make a single long blink
digitalWrite(ledPin, HIGH) ;
delay(600);
digitalWrite(ledPin, LOW) ;
delay(200);
}
void morseBlink(char character) {
/* morseBlink is a function that only deppends of one argument or parameter named character ( I choose that that name ). This parameter is a variable of char type, and char type is a number corresponding to ASCII characters */
// Translate character to Morse code
switch(character){
/* Switch is a common function in programming lenguages and is an alternative to "if, else" statements or instructions equivalent to
if characters == "s" */
case ‘s‘:
shortBlink();
shortBlink();
shortBlink();
break;
case ‘o‘:
longBlink();
longBlink();
longBlink();
break;
}
}
void loop() {
// Start blinking SOS
morseBlink(‘s‘);
morseBlink(‘o‘);
morseBlink(‘s’);
}