Page 195 - Programming the Photon Getting Started With the Internet of Things
P. 195
from 0 to 4095, where 4095 is 3V3. See Chapter 5 for more information on analog inputs.
Syntax
analogRead(pin);
Parameters
pin
The Photon board pin numbers A0–A5.
Return Value
An integer between 0 and 4095.
Example
int temperature = analogRead(pin);
This obtains the value from the analog pin and stores it in an integer variable called
temperature.
analogWrite
This sets the duty cycle of an analog pin, which is capable of pulse width modulation
(PWM). Remember we are using a digital system, so we can only emulate an analog
signal using PWM. This function sets the pin value between 0 and 255, where 0 is GND
and 255 is 3V3.
Syntax
analogWrite(pin, value);
Parameters
pin
The pin number.
value
An integer between 0 and 255.