source: rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestClient/CiaoRestClient.ino@ 175

Last change on this file since 175 was 175, checked in by ertl-honda, 8 years ago

ライブラリを Arduino IDE 1.7.9 にupdate

File size: 1.7 KB
Line 
1#include <Wire.h>
2#include <Ciao.h>
3
4#define CONNECTOR "rest"
5#define SERVER_ADDR "192.168.0.100" // change ip address with your server ip address
6
7int buttonState = LOW; //this variable tracks the state of the button, low if not pressed, high if pressed
8int ledState = -1; //this variable tracks the state of the LED, negative if off, positive if on
9long lastDebounceTime = 0; // the last time the output pin was toggled
10long debounceDelay = 50; // the debounce time; increase if the output flickers
11
12void setup() {
13 Ciao.begin();
14 pinMode(2, INPUT);
15
16}
17
18void loop() {
19
20 //sample the state of the button - is it pressed or not?
21 buttonState = digitalRead(2);
22
23 //filter out any noise by setting a time buffer
24 if ( (millis() - lastDebounceTime) > debounceDelay) {
25
26 //if the button has been pressed, lets toggle the LED from "off to on" or "on to off"
27 if ( (buttonState == HIGH) && (ledState < 0) ) {
28
29 CiaoData data = Ciao.write(CONNECTOR, SERVER_ADDR, "/arduino/digital/12/1"); //turn LED on
30 ledState = -ledState; //now the LED is on, we need to change the state
31 lastDebounceTime = millis(); //set the current time
32 }
33 else if ( (buttonState == HIGH) && (ledState > 0) ) {
34
35 CiaoData data = Ciao.write(CONNECTOR, SERVER_ADDR, "/arduino/digital/12/0"); //turn LED off
36 ledState = -ledState; //now the LED is off, we need to change the state
37 lastDebounceTime = millis(); //set the current time
38
39 if (!data.isEmpty()){
40 Ciao.println( "State: " + String (data.get(1)) );
41 Ciao.println( "Response: " + String (data.get(2)) );
42 }
43 else{
44 Ciao.println ("Write Error");
45 }
46
47 }
48
49 }
50
51}
Note: See TracBrowser for help on using the repository browser.