| Electronic Components Datasheet Search |
|
DEV-12887 Datasheet(PDF) 24 Page - SparkFun Electronics |
|
|
|||||||||||||||||||||||||||||
DEV-12887 Datasheet(HTML) 24 Page - SparkFun Electronics |
|
24 / 40 page ![]() ngly. // the table input should have parameters 'r', 'g', and 'b'. // This function will be called by the agent. function setRGB(rgbValue) { bluePin.write(rgbValue.b/255.0); redPin.write(rgbValue.r/255.0); greenPin.write(rgbValue.g/255.0); } // setUser will print out to the log the name of the LED chang er // This function will be called by the agent. function setUser(suspect) { server.log(suspect +" set the LEDs."); } // setTimer will turn the LEDs off after a specified number o f seconds // This function will be called by the agent. function setTimer(time) { if (time != 0) imp.wakeup(time, ledsOff); // Call ledsOff in 'time' s econds. } /////////////////////////////////// // Important Agent Handler Stuff // /////////////////////////////////// // Each object that the agent can send us needs a handler, whi ch we define with // the agent.on function. The first parameter in agent.on is an identifier // string which must be matched by the sending agent. The seco nd parameter is // the name of a function to be called. These functions are al ready defined up // above. agent.on("led", setLed); agent.on("rgb", setRGB); agent.on("user", setUser); agent.on("timer", setTimer); ////////////////////// // Helper Functions // ////////////////////// // ledsOff just turns all LEDs off. function ledsOff() { ledPin.write(0); redPin.write(0); greenPin.write(0); bluePin.write(0); } The key bit of new code in this example is the agent.on function call. Run during the setup portion of the code, these function calls set up a handler function to be called whenever the agent sends a specific string to the imp. For example, the agent.on("led", setLed); functions says that whenever a message tagged with an “led” string is received from the agent, call the setLed() function. Page 24 of 40 |
|
Link URL |
| Does ALLDATASHEET help your business so far? [ DONATE ] |
About Alldatasheet | Advertisement | Contact us | Privacy Policy | Link to Datasheet | Link Exchange | Manufacturer List All Rights Reserved©Alldatasheet.com |
| Russian : Alldatasheetru.com | Korean : Alldatasheet.co.kr | Spanish : Alldatasheet.es | French : Alldatasheet.fr | Italian : Alldatasheetit.com Portuguese : Alldatasheetpt.com | Polish : Alldatasheet.pl | Vietnamese : Alldatasheet.vn Indian : Alldatasheet.in | Mexican : Alldatasheet.com.mx | British : Alldatasheet.co.uk | New Zealand : Alldatasheet.co.nz |
|
Family Site : ic2ic.com |
icmetro.com |