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

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

1.7.10のファイルに更新

File size: 1.5 KB
Line 
1#include <Wire.h>
2#include <Ciao.h>
3
4#define CONNECTOR "rest"
5#define SERVER_ADDR "192.168.1.1" // change ip address with your server ip address
6
7int buttonState; //this variable tracks the state of the button, low if not pressed, high if pressed
8int ledState = HIGH; //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
11String command = "/arduino/mode/13/output";
12int previous_value = LOW;
13
14void setup() {
15 Ciao.begin();
16 Ciao.write(CONNECTOR, SERVER_ADDR, command);
17 pinMode(2, INPUT);
18
19}
20
21void loop() {
22
23 //sample the state of the button - is it pressed or not?
24 buttonState = digitalRead(2);
25
26 //filter out any noise by setting a time buffer
27 if ( (buttonState == HIGH) && (previous_value == LOW) && (millis() - lastDebounceTime) > debounceDelay ) {
28 if (ledState == HIGH){
29 command = "/arduino/digital/13/0";
30 ledState = LOW;
31 }
32 else{
33 command = "/arduino/digital/13/1";
34 ledState = HIGH;
35 }
36
37 lastDebounceTime = millis(); //set the current time
38 CiaoData data = Ciao.write(CONNECTOR, SERVER_ADDR, command);
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 previous_value = buttonState;
50
51}
Note: See TracBrowser for help on using the repository browser.