-
Notifications
You must be signed in to change notification settings - Fork 3
MATLAB Photon Coding Tutorial
Matt NT edited this page Aug 11, 2020
·
1 revision
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.
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.
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
g.connect()Connects Photon to cloud and Wi-Fi if disconnected.
Arguments
- None
Returns
- None
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.
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
g.disconnect()Disconnects the Photon from the Cloud and Wi-Fi if connected.
Arguments
- None
Returns
- None
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
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
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.
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
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
- Photon Pin Diagram
- Setting Up Your Photon
- Setting Up Your Photon to Work With MATLAB
- Photon-MATLAB Programming Tutorial
- MATLAB Tutorial