Go Down

Topic: Language Structure (Read 283 times) previous topic - next topic

kenmustunis

Please help me understand the following line of code:

void digital_1(void) //Display number 1

the word void in both cases is blue, what does this command mean?

groundFungus

#1
Feb 13, 2020, 11:25 pm Last Edit: Feb 13, 2020, 11:35 pm by groundFungus
The void on the left means that the function does not return a value.  The void on the right means that there are no arguments for the function to act upon.

The void on the right is optional.  The parenthesis are required but may be empty.  The void on the left is required when the function returns nothing.

Arduino functions

gfvalvo

The void on the right is optional.  The parenthesis are required but may be empty.  The void on the left is required when the function returns nothing.
The missing ';' at the end is mandatory.
No technical questions via PM. They will be ignored. Post your questions in the forum so that all may learn.

groundFungus

#3
Feb 14, 2020, 01:17 am Last Edit: Feb 14, 2020, 01:17 am by groundFungus
It is not exactly clear, to me, if that is a function declaration (; required) or the start of a function definition ({  //body;  } required).


kenmustunis

I still do not understand, in laymens terms, what does this line of code actually do?

TheMemberFormerlyKnownAsAWOL

It means you're formally introducing a function called "digital_1" that takes no parameters, and returns no value.
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

kenmustunis

Okay, i get that, now what exactly does " function called "digital_1" do?

TheMemberFormerlyKnownAsAWOL

Okay, i get that, now what exactly does " function called "digital_1" do?
We don't know, because you've introduced us, but not shown us it.
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

kenmustunis

Hope this helps. Here is the last few lines of code:

void digital_F(void) //Display F  // Question applies here, this line
{
unsigned char j;
digitalWrite(a,HIGH);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
digitalWrite(dp,HIGH);
}

void setup()
{
int i;//defined variable
for(i=4;i<=11;i++) //Set pinMode to all outputs in one step for all pins
pinMode(i,OUTPUT);//Set the 4 thru 11 pins for the output mode
}
void loop()
{
while(1)
{
digital_0();//Display number 0
delay(1000);//delay 1s
digital_1();//Display number 1
delay(1000);//delay 1s
digital_2();//Display number 2
delay(1000); //delay 1s
digital_3();//Display number 3
delay(1000); //delay 1s
digital_4();//Display number 4
delay(1000); //delay 1s
digital_5();//Display number 5
delay(1000); //delay 1s
digital_6();//Display number 6
delay(1000); //delay 1s
digital_7();//Display number 7
delay(1000); //delay 1s
digital_8();//Display number 8
delay(1000); //delay 1s
digital_9();//Display number 9
delay(1000); //delay 1s
digital_A();//Display Letter A
delay(1000); //delay 1s
digital_b();//Display Letter b
delay(1000); //delay 1s
digital_C();//Display Letter C
delay(1000); //delay 1s
digital_d();//Display Letter d
delay(1000); //delay 1s
digital_E();//Display Letter E
delay(1000); //delay 1s
digital_F();//Display Letter F
delay(1000); //delay 1s


}
}

TheMemberFormerlyKnownAsAWOL

#9
Feb 14, 2020, 10:10 pm Last Edit: Feb 14, 2020, 10:22 pm by TheMemberFormerlyKnownAsAWOL
Quote
Hope this helps.
No, not really.
We don't know what a,b,c,d,e,f,g or dp are, nor why j isn't used.
(It's a seven segment display, but that's an educated guess)

Please remember to use code tags when posting code.
Please don't PM technical questions - post them on the forum, then everyone benefits/suffers equally

groundFungus

Whoever wrote that code does not seem to know that loop() loops.

PerryBebbington

Okay, i get that, now what exactly does " function called "digital_1" do?
With all those delays in it it wastes a lot of time.

kenmustunis

As far as the delays are concerned, this program is being used  primarily to check the operation of our 7 segment displays returned to us as "Defective".  The a, b, c, d, e, f, g, are the actual segment displays and the dp is decimal point readout. to this response:Whoever wrote that code does not seem to know that loop() loops. I didn't write the code, I got it from a kit. This is what I'm trying to figure out what that line is doing...

jremington

Quote
This is what I'm trying to figure out what that line is doing.
If you re-read the previous posts, perhaps the provided explanations will become clear.

SteveMann

Hope this helps. Here is the last few lines of code:

void digital_F(void) //Display F  // Question applies here, this line
{
unsigned char j;
digitalWrite(a,HIGH);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
digitalWrite(dp,HIGH);
}
Here's the function cleaned up a bit:

Code: [Select]
void digital_F();   //Display F
{
  digitalWrite(a, HIGH);
  digitalWrite(b, LOW);
  digitalWrite(c, LOW);
  digitalWrite(d, LOW);
  digitalWrite(e, HIGH);
  digitalWrite(f, HIGH);
  digitalWrite(g, HIGH);
  digitalWrite(dp, HIGH);
}


From the others' comments, when this function is called, the segments making up the letter 'F' are lit.
The "unsigned char j;" in the function does absolutely nothing.

The code would not compile without the semicolon on the first line of the function.
Also, in the IDE, use CTRL-T to format the appearance of the code.

If you are just testing the display, you don't need to cycle through the alphabet.  Just light the segments one at a time, then all segments.  If one segment fails to light, then the display is bad.



Go Up