Changeset 224 for rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestClient/CiaoRestClient.ino
- Timestamp:
- Apr 30, 2016, 11:29:25 PM (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestClient/CiaoRestClient.ino
r175 r224 3 3 4 4 #define CONNECTOR "rest" 5 #define SERVER_ADDR "192.168. 0.100" // change ip address with your server ip address5 #define SERVER_ADDR "192.168.1.1" // change ip address with your server ip address 6 6 7 int buttonState = LOW; //this variable tracks the state of the button, low if not pressed, high if pressed8 int ledState = -1; //this variable tracks the state of the LED, negative if off, positive if on7 int buttonState; //this variable tracks the state of the button, low if not pressed, high if pressed 8 int ledState = HIGH; //this variable tracks the state of the LED, negative if off, positive if on 9 9 long lastDebounceTime = 0; // the last time the output pin was toggled 10 10 long debounceDelay = 50; // the debounce time; increase if the output flickers 11 String command = "/arduino/mode/13/output"; 12 int previous_value = LOW; 11 13 12 14 void setup() { 13 15 Ciao.begin(); 16 Ciao.write(CONNECTOR, SERVER_ADDR, command); 14 17 pinMode(2, INPUT); 15 18 … … 20 23 //sample the state of the button - is it pressed or not? 21 24 buttonState = digitalRead(2); 22 25 23 26 //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 27 if ( (buttonState == HIGH) && (previous_value == LOW) && (millis() - lastDebounceTime) > debounceDelay ) { 28 if (ledState == HIGH){ 29 command = "/arduino/digital/13/0"; 30 ledState = LOW; 32 31 } 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 32 else{ 33 command = "/arduino/digital/13/1"; 34 ledState = HIGH; 47 35 } 48 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 49 47 } 50 48 49 previous_value = buttonState; 50 51 51 }
Note:
See TracChangeset
for help on using the changeset viewer.