As the title says... Chat on...

User avatar
By seedseifer
#58580 Hello all,

I need something similar to "Pulsein()" function in nodemcu but i have no clue how to do that, Im trying to interface with hc-sr04 module with some results but very different than ones from arduino.

Any one know a good lib for lua?

Thks in advance
User avatar
By seedseifer
#58687 thks, but i get a lot of unstable results, so i tryed arduino way....works.

I need this code in lua format:
Code: Select all#define TRIGGER 0
#define ECHO 2 // NodeMCU Pin D0 > TRIGGER | Pin D2 > ECHO
void setup() {
  Serial.begin (9600);
  pinMode(TRIGGER, OUTPUT);
  pinMode(ECHO, INPUT);
  //pinMode(BUILTIN_LED, OUTPUT);
  }
   
void loop() {
 long duration, distance;
 digitalWrite(TRIGGER, LOW);
 delayMicroseconds(2);
 digitalWrite(TRIGGER, HIGH);
 delayMicroseconds(10);
 digitalWrite(TRIGGER, LOW);
 duration = pulseIn(ECHO, HIGH);
 distance = (duration/2) / 29.1;
 Serial.print(distance);
 Serial.println("Centimeter:");
 delay(1000);
 }