MATLAB Photon Coding Tutorial - MAE221/Thermodynamics-Lab GitHub Wiki

Constructor

g = Photon(String name, String access_token, String port)

Arguments

  • String name - Photon ID or Photon name retrieved from Photon setup.
  • String access_token - Authorization token retrieved from Particle CLI.
  • String port - Serial port Photon is connected to

Returns

  • A Photon object that knows how to access the following functions and methods.

Functions

analogRead

output = g.analogRead(String pin)

Sample the voltage of an analog pin.

Arguments

  • String pin - The name of the pin connected to sample.

Returns

  • A value corresponding to 0-3.33V.

analogWrite

g.analogWrite(String pin, Int Value)

Writes a voltage value to an analog pin.

Arguments

  • String pin - The name of the pin connected to sample.
  • Int value - The bit value to write. Takes a value between 0-3.33V.

Returns

  • Voltage outputted

connect

g.connect()

Connects Photon to cloud and Wi-Fi if disconnected.

Arguments

  • None

Returns

  • None

digitalRead

output = g.digitalRead(String pin)

Sample the bit value of a digital pin.

Arguments

  • String pin - The name of the pin connected to sample.

Returns

  • The bit value at that pin. Takes value of 0 for LOW and 1 for HIGH.

digitalWrite

g.digitalWrite(String pin, Int Value)

Writes a bit value to a digital pin.

Arguments

  • String pin - The name of the pin connected to sample.
  • Int value - The bit value to write. Takes a value of 0 or 1 corresponding to HIGH or LOW.

Returns

  • Value written

disconnect

g.disconnect()

Disconnects the Photon from the Cloud and Wi-Fi if connected.

Arguments

  • None

Returns

  • None

getPin

intValue = g.getPin(String pin)

Converts the name of the string to the integer value associated with that pin.

Arguments

  • String pin - The name of the pin connected to get the integer value of.

Returns

  • Integer value of the pin

getPinMode

mode = g.getPinMode(String pin)

Prints whether a pin is an input or output pin

Arguments

  • String pin - The name of the pin connected to get the mode of.

Returns

  • None

isConnected

connection = g.isConnected()

Tells whether the Photon is connected to the internet or not.

Arguments

  • None

Returns

  • Returns True if the device associated with the Photon's name is connected to the internet and False if the device is not.

setInput

g.setInput(String pin)

Designates a pin to be an input pin

Arguments

  • String pin - The name of the pin connected to sample.

Returns

  • 1 if successful, -1 if already designated as an input/output

setOutput

g.setOutput(String pin)

Designates a pin to be an output pin

Arguments

  • String pin - The name of the pin connected to sample.

Returns

  • 1 if successful, -1 if already designated as an input/output