Hello World App for Photon

When learning a new coding language, many people first create what is called a "Hello World" program. Traditionally, this involves displaying the text "Hello World" on the screen. The purpose is to demonstrate that you can create a simple working program in the new coding language.

Creating a working device with an electronics kit involves both building the physical device and programming it. So if your device doesn't work as expected, the reason could be that some of the parts are connected incorrectly – or the program might have a mistake – or it could be both.

So you will create a different kind of "Hello World" app for your Photon device: an app that doesn't require connecting any additional parts to the Photon, so you can first focus on getting some code to work.

The Photon has a built-in blue LED light that is connected to its D7 pin. This "Hello World" app will turn this blue LED on and off in a repeating pattern. This will be your first app before you start to connect additional parts to program more complex devices.

This app – like all apps that run on Photon devices – is coded in a programming language called Wiring. Here's an overview of the Wiring programming language.

WHAT TO DO

  1. Login to your Particle Build account. If necessary, here's a brief overview of navigating and using Particle Build.

  2. Create a new app titled: hello-world

  3. Delete the placeholder code that Particle Build inserted for your new app (the empty setup() and loop() functions).

  4. Copy and paste the code below into your new app. Save the app in Particle Build, and then load ("flash") the app onto your Photon device. During "flashing", Particle Build transfers the app to your device over Wi-Fi. The RGB light on your Photon blinks magenta as the new app is being flashed, and then the Photon restarts. Be patient – sometimes it takes longer for your first app to flash because Particle may need to also update the firmware (OS) on your Photon device.

  5. After the Photon has reconnected to Wi-Fi, the new app will automatically start running. If everything worked correctly, the blue D7 LED on your Photon device should blink on and off repeatedly. It may not seem like much, but you've just taken your first step in coding with the Wiring language.

  6. Once you get the app working, try modifying the code to change the LED blinking pattern. Flash your modified app to your Photon to see what your changes do. Can you make the LED blink faster? Can you make it blink slower? Can you make it blink in a more complex pattern (maybe similar to Morse code)?

Code for Hello-World

// HELLO WORLD app - introductory program that doesn't require connecting any parts

// GLOBAL VARIABLES - variables that will be used in multiple functions
// declare integer variable called "led" and assign it value of D7 (built-in LED)
int led = D7;

// SETUP function runs one time at start when device is powered on
void setup() {
    // set "led" pin to be an output
    pinMode(led, OUTPUT);
}

// LOOP function runs in repeating loop (after setup finishes)
void loop() {
    // turn on "led" pin (built-in blue LED light)
    digitalWrite(led, HIGH);

    // wait 1 second (1000 milliseconds)
    delay(1000);

    // turn off "led" pin
    digitalWrite(led, LOW);

    // wait 1 second
    delay(1000);

    // loop repeats itself again
}

A couple of things to note about the code:

  • The lines that begin with two forward slashes are comments. Comments are just notes for people reading the code. The comments are ignored by the device when the app runs. Comments are optional, but it can be helpful to include comments to explain certain parts of the app.

  • Integers are supposed to be whole numbers, but the Wiring language treats input and output pin names (D7, etc.) as "integer" variables.

Last updated