04 - EE 2361 Introduction to Microcontrollers UMN Fall 2015...

This preview shows page 1 - 3 out of 5 pages.

EE 2361 UMN Introduction to Microcontrollers Fall 2015 Lab # 4 In this lab, you’ll begin interacting with the Photon in a meaningful way. Recall from lecture how you define and use a Spark.function . Here is the most basic example: int ledPin = D7 ; void setup () { pinMode ( ledPin , OUTPUT ); Spark . function ( "led" , ledSwitcher ); } void loop () { } int ledSwitcher ( String command ) { if ( command . equalsIgnoreCase ( "on" )) { digitalWrite ( ledPin , HIGH ); return 1; } else if ( command . equalsIgnoreCase ( "off" )) { digitalWrite ( ledPin , LOW ); return 1; } return -1; } This code switches the LED on pin D7 of the Photon on or off when the Spark.function named led is called with the parameter “ on ” or “ off ”. You can call it via the command line, with curl: curl >/led -d access_token=<accesstoken> -d params=on
EE 2361, Fall’ 15 2 Here <deviceid> is the ID of your Photon. You can find this under “Devices” at build.particle.io . <accesstoken> is the token for your Particle account. You can find this under “Settings” at

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture