Understanding some arduino code

camochase

Well-Known Member
OP
Member
Joined
Oct 26, 2010
Messages
164
Trophies
0
Age
26
XP
294
Country
United States
So im looking at some code that takes the data of a snes controller and displays what is being pressed in the debug. I have never used arduino so im just trying to understand it it says
Code:
if (ControllerData & SNES_B) {
Serial.print(" B");
}
what exactly does the & symbol do in the condition?
 

ResleyZ

Swiggity swaggity swooty, I love my own booty
Member
Joined
Oct 11, 2013
Messages
528
Trophies
1
Age
29
Location
Silicon Valley
XP
544
Country
Netherlands
It seems that Arduino uses either C+ or C++, in which case the & symbol shows where the address will be taken from. In this case it takes the ControllerData from SNES_B. It might be useful to read a little introduction to C++, since it is always helpful to understand the basics. Not sure though, so I may be wrong :P
 

Foxi4

Endless Trash
Global Moderator
Joined
Sep 13, 2009
Messages
30,844
Trophies
3
Location
Gaming Grotto
XP
29,930
Country
Poland
  • Like
Reactions: PityOnU

camochase

Well-Known Member
OP
Member
Joined
Oct 26, 2010
Messages
164
Trophies
0
Age
26
XP
294
Country
United States
I do understand C but the problem was i couldnt see how it was a condition that would work with an if statement but foxi4's comment on how it helps distinguish between buttons helped alot and sorry for not posting what controller data and things are
 

Foxi4

Endless Trash
Global Moderator
Joined
Sep 13, 2009
Messages
30,844
Trophies
3
Location
Gaming Grotto
XP
29,930
Country
Poland
understand C but the problem was i couldnt see how it was a condition that would work with an if statement but foxi4's comment on how it helps distinguish between buttons helped alot and sorry for not posting what controller data and things are

If you don't have a comparison operator in an if statement, the the compiler assumes that you mean if(statement is true?). :)
 

PityOnU

Well-Known Member
Member
Joined
Jul 5, 2012
Messages
1,184
Trophies
1
XP
1,619
Country
United States
It seems that Arduino uses either C+ or C++, in which case the & symbol shows where the address will be taken from. In this case it takes the ControllerData from SNES_B. It might be useful to read a little introduction to C++, since it is always helpful to understand the basics. Not sure though, so I may be wrong :P

Arduino code is closer to Java, so... not even close.

Snaps for Foxi.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
  • light27 @ light27:
    wait what? oh
  • light27 @ light27:
    my bad
  • light27 @ light27:
    happy birthday
  • light27 @ light27:
    OIP.19q3E5NK_Mdn0K35CZWrWQHaJ4
    for you bro
    +2
  • Xdqwerty @ Xdqwerty:
    @light27, it's actually tommorrow but thx
  • light27 @ light27:
    oh it’s the least I could do
    +1
  • K3Nv2 @ K3Nv2:
    yawn
  • Xdqwerty @ Xdqwerty:
    @K3Nv2, stop stealing my phrases
  • K3Nv2 @ K3Nv2:
    why
  • Xdqwerty @ Xdqwerty:
    @K3Nv2, it's not funny
  • K3Nv2 @ K3Nv2:
    ok
  • BigOnYa @ BigOnYa:
    Wut?
  • K3Nv2 @ K3Nv2:
    That's not funny
    +1
  • Psionic Roshambo @ Psionic Roshambo:
    So two cannibals where eating a clown and one says to the other. Hey does this taste funny to you?
    +1
  • K3Nv2 @ K3Nv2:
    What do you call a slow car? Retired
    +1
  • Psionic Roshambo @ Psionic Roshambo:
    Did you hear about the police car that someone stole the wheels off of? The police are working tirelessly to find the thieves.
    +1
  • K3Nv2 @ K3Nv2:
    A firefighter got arrested for assault his main claim was what I was told he was on fire
    +1
  • BigOnYa @ BigOnYa:
    What do you call a hooker with a runny nose? Full
    +1
  • Psionic Roshambo @ Psionic Roshambo:
    What do you tell a woman with two black eyes? Nothing you already told her twice!
  • K3Nv2 @ K3Nv2:
    Diddy also works
  • K3Nv2 @ K3Nv2:
    A scientist heard the word batman so he put a naked lady in a cage with a bat
  • Psionic Roshambo @ Psionic Roshambo:
    Chuck Norris won a staring contest, with the sun.
  • K3Nv2 @ K3Nv2:
    A vampires favorite thing to do is moon you
  • BigOnYa @ BigOnYa:
    What's the difference between an airplane, and Ken's mom? Not everyone has been in an airplane.
    BigOnYa @ BigOnYa: What's the difference between an airplane, and Ken's mom? Not everyone has been in an airplane.