Page 73 - Programming the Photon Getting Started With the Internet of Things
P. 73
digital pin D0 on the Photon board.
Here is the firmware that we will load to the Photon board:
int digitalpin = D0;
void setup() {
pinMode(digitalpin, OUTPUT);
}
void loop() {
digitalWrite(digitalpin, HIGH);
delay(1000);
digitalWrite(digitalpin, LOW);
delay(1000);
}
At the start of the program in the setup and loop functions you can see the command
pinMode. You use this command every time you are using a pin on the Photon, whether
this is an input pin or an output pin. This allows the Photon board to configure the
electronics connected to that pin and allows us to control them using some simple
commands in the firmware.
As you may already know from the previous chapters, certain functions are built-in,
and pinMode is one of those functions. Its first argument is the pin number that the
function is referring to. This pin number is an integer value represented by a number. The
second argument is the mode, which must either be an INPUT or OUTPUT.
NOTE The mode value must always be uppercase.
The loop part of the program switches the digital pin on the Photon board to HIGH
and waits for one second in the delay and then sets the pin back to LOW and waits another
second before repeating the process.
So with the multimeter turned on and plugged into the Photon board, you should be
able to see its readings change from 0 V to 3.3 V as the firmware runs, as shown in Figure
4.2. This is a simple way of showing how the digital pins work as they send the voltage
from 0 V to 3.3 V using the command DigitalWrite and setting the argument to HIGH or
LOW.