Go Down

Topic: what does this line of code do? (Read 835 times) previous topic - next topic

sirbow2

Code: [Select]
  val = analogRead(potPin);
  amp = (val >= 512) ? val - 512 : 512 - val;

the first one reads the analog pin, obviously, but what does the second line do?

mainly what is:
Code: [Select]
? val - 512 : 512 - val

thanks
http://dduino.blogspot.com all my Arduino/electronic projects!!!

{NEW} Getting Started, Learning, Reference + FAQ PDF!!:
[url]http://ar

pYro_65

it is a ternary operator.

X = A ? B : C;

if A is true X = B, otherwise C
Forum Mod anyone?
https://arduino.land/Moduino/

sirbow2

http://dduino.blogspot.com all my Arduino/electronic projects!!!

{NEW} Getting Started, Learning, Reference + FAQ PDF!!:
[url]http://ar

Go Up