Ignore:
Timestamp:
Apr 30, 2016, 11:29:25 PM (8 years ago)
Author:
ertl-honda
Message:

1.7.10のファイルに更新

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rtos_arduino/trunk/arduino_lib/libraries/Ciao/examples/CiaoRestClient/CiaoRestClient.ino

    r175 r224  
    33
    44#define CONNECTOR     "rest"
    5 #define SERVER_ADDR   "192.168.0.100" // change ip address with your server ip address
     5#define SERVER_ADDR   "192.168.1.1" // change ip address with your server ip address
    66
    7 int buttonState = LOW; //this variable tracks the state of the button, low if not pressed, high if pressed
    8 int ledState = -1; //this variable tracks the state of the LED, negative if off, positive if on
     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
    99long lastDebounceTime = 0;  // the last time the output pin was toggled
    1010long debounceDelay = 50;    // the debounce time; increase if the output flickers
     11String command = "/arduino/mode/13/output";
     12int previous_value = LOW;
    1113
    1214void setup() {
    1315  Ciao.begin();
     16  Ciao.write(CONNECTOR, SERVER_ADDR, command);
    1417  pinMode(2, INPUT);
    1518 
     
    2023  //sample the state of the button - is it pressed or not?
    2124  buttonState = digitalRead(2);
    22  
     25  
    2326  //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;
    3231    }
    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;
    4735    }
    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
    4947  }
    5048 
     49  previous_value = buttonState;
     50 
    5151}
Note: See TracChangeset for help on using the changeset viewer.