How to create conditional statement and push button


#1

hi,
I have two question. first one is I want to see if an input pin LOW, or HIGH. for example if a door is open I want it will be written in “Door Open” text widget. if closed Door closed must be written according to arduino pins state.

the second one how can I create push button effect with switch as because there is no push button widget in dashboard.

thanks for ideas.


#2

Hi!

Por the push button you can define a resource like the following:

thing["open"] << [](pson& in){ 
   if(in.is_empty()){
       in = false;
   }
   else{
       digitalWrite(pin, HIGH); delay(300); digitalWrite(pin,LOW); 
   }
};

When you configure a button over this resource, you will see how it is activated, and after 300 milliseconds, it turn off again. You should define the pin to control, and also the momentary HIGH time (300 ms in this example).

For defining a resource that show open or close, you must create it in the source. At this moment it is not supported in the console. So you can implement it as the following:

thing["state"] >> [](pson& out){
    out = digitalRead(statePin) == HIGH ? "Door Open" : "Door Closed";
};

Hope it helps!


#3

it works great. thank you for valuable information.


#4

Hi,

if I want to display a statement on a servo, if the rotation is 90 degrees “open” and the rotation is 0 degrees “closed”… can you help ?
thanks…