Digital output with 100ms ON and back to Off immediately

Hello all,

As the subject above, how to make an output with ON 100ms and then back to Off immediately using thingerio library?
I’ve tried to write the code with thingerio library on NodeMCU microcontroller, but it seems not working. My simple code is like this :

void setup() {
Serial.begin(115200);
Serial.println();
pinMode(machine_on, OUTPUT);
delay(10);
thing.add_wifi(SSID, SSID_PASSWORD);
thing[“Machine_On”]<< digitalPin(15);
{
digitalWrite(machine_on, HIGH); // Get Start
delay(100); // sending delay 100ms
digitalWrite(machine_on, LOW); // get low
delay(100); // delay
}
void loop() {
thing.handle();
}

Anybody have tried the same?

Is it called by pin 15 state or how?

Hello @astonix

I’m not preaty sure about what do you want to do but there is one mistake in your resource definition, the right lambda structure for your case should be like:

thing[“Machine_On”]<<[](pson & in) {
    if(in.is_empty()){
      in=(bool)digitalRead(15);
    }else{
      digitalWrite(15, in ? HIGH : LOW); //Here is the control of the GPIO15
      digitalWrite(machine_on, HIGH); // Get Start
      delay(100); // sending delay 100ms
      digitalWrite(machine_on, LOW); // get low
      //delay(100); // this is not necessary
    }
}; //Remember to put the ';' here

and if you want to turn the slider and the led off after the 100ms just add something like this:

thing[“Machine_On”]<<[](pson & in) {
    if(in.is_empty()){
      in=(bool)digitalRead(15);
    }else{
      if(in==true){ 
          digitalWrite(15,HIGH ); //Here is the control of the GPIO15
          digitalWrite(machine_on, HIGH); // Get Start
          delay(100); // sending delay 100ms
          digitalWrite(machine_on, LOW); // get low
          digitalWrite(15,LOW );
          in=flase;  //this will turn the switch off
    }
}; //Remember to put the ';' here

Let me know if this works fine for you
best!

Thank you!
The first one is works perfectly. I got error for the last code, but nevermind, the first code also make LED and slider goes Off after 100ms.

FYI, i make this to replace coin drop module for machine that is still use coin for activation. That’s why, i need to send only 100ms signal then back to Off the same as coin drop module work.
Using this, user can monitor transaction cycle for each machine.

Best.

1 Like