Help with basics

Hello,
I have been working on this code. mainly trying to learn some things about loops. Im guessing someone will spot my mistake fairly easy.

int frank1 = 8;
int peter1 = 9;
int led3 = 10;
int led4 = 11;

void setup()

{Serial.begin(9600);
 pinMode(frank1, OUTPUT);
 pinMode(peter1, OUTPUT);
 pinMode(led3, OUTPUT);
 pinMode(led4, OUTPUT);}

void loop()

{ void frank();
  void peter();
  void paul();
  void bobby();}
  
void frank()

{ if(Serial.available() >1)
 {  digitalWrite(frank1, HIGH);
    delay(300);
    digitalWrite(frank1, LOW);
    delay(300);}}

void peter()

{ if(Serial.available() >1)
 {  digitalWrite(peter1, HIGH);
    delay(300);
    digitalWrite(peter1, LOW);
    delay(300);}}

void paul()

{ if(Serial.available() >1)
 {  digitalWrite(led3, HIGH);
    delay(300);
    digitalWrite(led3, LOW);
    delay(300);}}

void bobby()

{ if(Serial.available() >1)
 {  digitalWrite(led4, HIGH);
    delay(300);
    digitalWrite(led4, LOW);
    delay(300);}}

What do you expect to happen?

Whenever more than one character is received, Serial.available() >1 will be true.
Since you never read those characters, Serial.available remains >1 hence the functions will execute forever.

What are you trying tho do.

Put { and } on lines by themselves.
Use CTRL T to format your code.

void frank(); this is not the way to call a function, it is a prototype.
.

oh ok. I see why you dont get it. Im sorry thats my bad. I was only using serial to as a trigger. Is that ok to do?

You can, but I don't see the reason to do this.

void frank(); this is a function prototype, the IDE does not need you to do it.
frank(); this calls the actual function.

.

It's merely for learning. Understanding.

The way I set the {and} was just to make it easier for me to read. will this change the way my code works? I try to keep them in order.

control-T big thanks. point noted.

As for void frank(), I have been seeing things set this way here take a peek.

too long to copy:

http://forum.arduino.cc/index.php?topic=223286.0

thank you!

As for void frank(), I have been seeing things set this way here take a peek.

As may be, but your still WRONG!

Just as you where in your other thread about the same problem Due or Improve? Your take thanks. - Project Guidance - Arduino Forum

Mark

Since you are learning the basics, start to follow good programming techniques.
Place { and } on separate lines.

void frank();
is quite different from
frank();

Do you see the difference in the following three examples?

void frank(); <-----<<<< this is a function prototype
frank(); <-----<<<< this is how to call the function

void frank() <-----<<<< this is the function
{
. . .
}

.

Ran into this just last night.

called a function in my setup

bla;
bla;
void fileCleaner();
bla;
bla;

fileCleaner() got a real good going over, cleanup and rewrite before I realized my mistake. The compiler didn't care that it was in the middle of the code. But it never got called written that way.

-jim lee

That will happen a few times until it won't anymore :wink:

.

jimLee:
Ran into this just last night.

called a function in my setup

bla;

bla;
void fileCleaner();
bla;
bla;




fileCleaner() got a real good going over, cleanup and rewrite before I realized my mistake. The compiler didn't care that it was in the middle of the code. But it never got called written that way.

-jim lee

It's also worth remembering that the function "bla" never got called either.

#define bla Serial.println("High Groove")

.

LarryD:
#define bla Serial.println("High Groove")

.

Respect. 8)

@jrgreen, if you are still here and are serious about learning the basics.

IF you are and IF you can attempt to solve a computer game WITHOUT looking up the solution on the net..

'Cause if you look it up its just wasted effort.

Grab this game : Human resource machine

And play it without googling anything.

It'll help. Just like "Wax on, Wax off"

-jim lee

This works and leaves output in Serial Monitor (set it to 250000 baud).
You can enter text over and over and see how it acts, not just go by leds flashing.

I added a loop in setup() since you want to learn more about those.

Be sure to read the comments and ask about what you didn't 'get'.

int frank1 = 8;
int peter1 = 9;
int led3 = 10;
int led4 = 11;

void frank()
{
  if (Serial.available()) // not 0 is true
  { // this runs if there's data
    char ch = Serial.read(); // read one removes one
    // if you don't remove the char it stays available
    Serial.print( "Frank " );
    Serial.println( ch );

    digitalWrite(frank1, HIGH );
    delay(300);
    digitalWrite(frank1, LOW);
    delay(300);
  }
}

void peter()
{
  if (Serial.available())
  {
    char ch = Serial.read();
    Serial.print( "Peter " );
    Serial.println( ch );

    digitalWrite(peter1, HIGH);
    delay(300);
    digitalWrite(peter1, LOW);
    delay(300);
  }
}

void paul()
{
  if (Serial.available())
  {
    char ch = Serial.read();
    Serial.print( "Paul S " );
    Serial.println( ch );

    digitalWrite(led3, HIGH);
    delay(300);
    digitalWrite(led3, LOW);
    delay(300);
  }
}

void bobby()
{
  if (Serial.available())
  {
    char ch = Serial.read();
    Serial.print( "Bobby " );
    Serial.println( ch );

    digitalWrite(led4, HIGH);
    delay(300);
    digitalWrite(led4, LOW);
    delay(300);
  }
}

byte countUp; // default is 0

void setup()
{
  Serial.begin( 250000); // set Serial Monitor to match
  Serial.println( "\nCounting with a LOOP" );

  while ( countUp < 10 )
  {
    Serial.println( countUp );
    countUp++; // adds 1 to countUp
  }

  Serial.println( "\n now enter text from Serial Monitor\n" );
}

void loop()
{ // this brace and the } below BELONG to void loop()
  // put right after, it's easier to see that.

  frank();
  peter();
  paul();
  bobby();
} // this } is on the same level as the matching {
// that way it is easier to match them up

// it is not "cool" to pack code in ways that make
// it harder to quickly see where one thing begins
// and ends. it's really kind of "fool yourself"
// SMART is making and keeping things clear

Thats great info.

LarryD

void frank(), how is void frank different then void loop plz. my guess at it was it was a loop with a unique name(and maybe timing. thats what i was about to find out) inside
of void loop? Does this mean void loop would also be considered a function?

Jimmylee

Not sure if that game would be helpfull or not. I did look into it as you asked got to the part where it asked for 9.99. you understand.

GoForSmoke

Priceless to me that you did that.

I was down 16hrs just seen all this.
From the looks of it I will be studying for a good stretch just with what has already been provided to me

I mean guys Im still making sure I understand what functions are.

I once knew a John Greene who lived in southeast PA. He'd be almost 60 by now.