Understanding some arduino code

  • Thread starter Thread starter camochase
  • Start date Start date
  • Views Views 1,442
  • Replies Replies 6

camochase

Well-Known Member
Member
Joined
Oct 26, 2010
Messages
164
Reaction score
6
Trophies
0
Age
28
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?
 
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
 
  • Like
Reactions: PityOnU
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
 
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?). :)
 
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