Trying to learn how to use functions within a loop.

I'm attempting to use a function and a loop counter within functions in order to create an SOS signal.

Im getting an error code that Im not sure how to resolve. I want to:

set up an LED to flash an sos

call subroutine S
delay
call subroutine O
delay
call subroutine S

loop

Sub s
count for 3
on
delay
off
delay
repeat

sub 0
same as above

Here is my code: could someone please point out why It might not be working?

thanks

const int LED=13; //Call pin 13 LED

int scount=0;
int ocount=0;

void setup() {
pinMode(LED,OUTPUT); //Make LED an output device

}

void loop() {
sends() //call S subroutine
delay(50);
sendo(); //call O subroutine
delay(50);
sends()
delay(1300);
}

sends(){
for (int scount=0; scount<3; scount++){
digitalWrite(LED,HIGH); //Turn on LED
delay(10); //wait 0.01
digitalWrite(LED,LOW); //turn LED off
delay(200); //wait 0.25 Sec
} //wait 0.7 Sec
}

send0(){
for (int ocount=0; ocount<3; ocount++}){
digitalWrite(LED,HIGH);
delay(50);
digitalWrite(LED,LOW);
delay(20);
}
}

You have not posted the error message you are getting.

You have a lot of delay()s in your program. If you literally only want to flash an SOS messsage that should be fine. But if you are thinking of anything more complex it would probably be wise to use millis() to manage your timing without blocking the Arduino in the way that delay() does.

Have a look at how millis() is used to manage timing without blocking in Several Things at a Time.

And see Using millis() for timing. A beginners guide if you need more explanation.

...R

EVERY line needs to end with a ;, not random lines.

Your functions need a return type before their name. If nothing is to be returned then the return type is void as it is for loop() and setup()

And sendo is not the same as sendO

And a for loop does not usually have a } in it

PaulS:
EVERY line needs to end with a ;, not random lines.

Not quite every line

You were missing some semicolons at the ends of statements.
You didn't declare the return value type on your two functions (use the type 'void' if not value is returned).
You had an extra '}' in one of your loops.
You had comments where they weren't needed.
You had comments that did not match the code.
You had many integer constants without names.
You had global AND local variables with the same name. The globals were not used.
You used 'scount' and 'ocount' variable names even though they were local and could both be called 'count'.

This is how I would have done it:

const unsigned DashTime = 300;
const unsigned DotTime = 70;
const unsigned TimeBetweenSignals = 150;
const unsigned TimeBetweenLetters = 250;


void setup()
{
  pinMode(LED_BUILTIN, OUTPUT);
}


void loop()
{
  sendS();
  delay(TimeBetweenLetters);
  sendO();
  delay(TimeBetweenLetters);
  sendS();
  delay(1300);
}


void sendS()
{
  for (int count = 0; count < 3; count++)
  {
    dot();
    delay(TimeBetweenSignals);
  }
}


void sendO()
{
  for (int count = 0; count < 3; count++)
  {
    dash();
    delay(TimeBetweenSignals);
  }
}


void dash()
{
  digitalWrite(LED_BUILTIN, HIGH);
  delay(DashTime);
  digitalWrite(LED_BUILTIN, LOW);
}


void dot()
{
  digitalWrite(LED_BUILTIN, HIGH);
  delay(DotTime);
  digitalWrite(LED_BUILTIN, LOW);
}