User Tools

Site Tools


oak:tutorials:particle-function

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
oak:tutorials:particle-function [2016/03/24 18:52]
jwhendy finished up code sections
oak:tutorials:particle-function [2016/05/27 01:30] (current)
pfeerick edited to hopefully reduce confusion on how Particle.function is used in code
Line 1: Line 1:
-===== Oak: using Particle.variable() ===== +===== Oak: using Particle.function() =====
- +
-[[http://​digistump.com/​wiki/​_media/​oak-rgb-led.png|{{http://​digistump.com/​wiki/​_media/​oak-rgb-led.png?​400}}]]+
  
 This tutorial is very similar to the one on [[http://​digistump.com/​wiki/​oak/​tutorials/​particle-variable|Particle.variable()]]. This time, however we will be doing the reverse: //sending// data to the Oak. To accomplish this, we use ''​Particle.function()''​. As an example, we will send ''​POST''​ commands using ''​curl''​ to the Particle API which will control the color of an RGB led connected to the Oak. This tutorial is very similar to the one on [[http://​digistump.com/​wiki/​oak/​tutorials/​particle-variable|Particle.variable()]]. This time, however we will be doing the reverse: //sending// data to the Oak. To accomplish this, we use ''​Particle.function()''​. As an example, we will send ''​POST''​ commands using ''​curl''​ to the Particle API which will control the color of an RGB led connected to the Oak.
Line 18: Line 16:
 |Resistor, 220 ohm| 3 | Red-Red-Brown| |Resistor, 220 ohm| 3 | Red-Red-Brown|
  
-These are the same components used with the [[http://​digistump.com/​wiki/​oak/​tutorials/​rgb-led#​components_used|advanced ​LED tutorial]]. Feel free to substitute any resistor value between 100-1k ohms.+These are the same components used with the [[http://​digistump.com/​wiki/​oak/​tutorials/​rgb-led#​components_used|RGB LED tutorial]]. Feel free to substitute any resistor value between 100-1k ohms.
  
 **Note:** You need to install [[https://​curl.haxx.se/​download.html|curl]] to push data to the Particle API. **Note:** You need to install [[https://​curl.haxx.se/​download.html|curl]] to push data to the Particle API.
Line 28: Line 26:
 This function creates an interface between your Oak and particle.io. We create a function with a given name, and then access that named function via ''​curl''​ commands, passing along a value with it. On the Oak side, it finds the function with that name, and then runs it with the value that was passed. This function creates an interface between your Oak and particle.io. We create a function with a given name, and then access that named function via ''​curl''​ commands, passing along a value with it. On the Oak side, it finds the function with that name, and then runs it with the value that was passed.
  
-The syntax looks like this:+The syntax looks like ''​Particle.function("​name",​ function_name)'',​ and you then have a function that look like the below example, which is run when the function is triggered. You would normally place the ''​Particle.function''​ command in the setup() portion of your code. Have a look at the example sketch at the bottom of the page to better understand how function is used.
  
 <​code>​ <​code>​
-Particle.function("​name",​ function_name) 
- 
 int function_name(String arg) int function_name(String arg)
 { {
Line 207: Line 203:
   Particle.function("​set",​ set_rgb);   Particle.function("​set",​ set_rgb);
   ​   ​
-  // we'll configure the on-board LED to blink +  // initialize each color pin as an output
-  // this is handy for simply making sure the Oak is running your sketch+
   pinMode(6, OUTPUT);   pinMode(6, OUTPUT);
   pinMode(7, OUTPUT);   pinMode(7, OUTPUT);
oak/tutorials/particle-function.1458870721.txt.gz · Last modified: 2016/03/24 18:52 by jwhendy