- Fanged Lawn Wormy
- Jan 4, 2008
-
SQUEAK! SQUEAK! SQUEAK!
|
I'm working on an Arduino thing for work and I'm trying to make use of Structs to make things a little easier. Problem is, I don't know a lot about them! I also am a little fuzzy on pointers and referencing, so as you can imagine, this is tough for me.
So, I want to be a be able to pass a struct into a function and have it modify the data in the struct, either directly or returning the info. What's the best way to do that?
I have something along these lines:
code:struct Player
{
uint8_t Button1_Pin;
uint8_t Button2_Pin;
uint8_t State;
uint8_t Score;
}
Player Player1;
Player Player2;
and I'm thinking of trying to do something like this:
code:void Read_Player(struct *ThePlayer)
{
if(digitalRead(ThePlayer->Button1_Pin) == LOW)
{
ThePlayer->Score++;
State = true;
}
if(digitalRead(ThePlayer->Button2_Pin) == LOW)
{
State = false;
}
}
void loop()
{
Read_Player(&Player1);
Read_Player(&Player2);
}
Now, I'm just kind of awkwardly thinking this out right now, I haven't even tried to compile, and I don't have a controller handy on me to see if it works... am I in the right direction? I imagine I'm missing something.
|
#
¿
May 28, 2018 16:25
|
|
- Adbot
-
ADBOT LOVES YOU
|
|
#
¿
Apr 29, 2024 06:36
|
|
- Fanged Lawn Wormy
- Jan 4, 2008
-
SQUEAK! SQUEAK! SQUEAK!
|
ah yeah forgot to do the membering there.
And I wouldn't have to do a return, correct? Because this manipulating the original data, rather than passing a copy.
|
#
¿
May 28, 2018 16:59
|
|