Hi everyone, I am trying to create a program for a robot which uses an HC-SR04 ultrasonic sensor and an SG90 servo. I've got the HC-SR04 reading values reliably after tweaking the timing and clock speed a bit (values are about 1.5 inches off but that can easily be compensated for using simple arithmetic). The problem is when I introduce the IF structure. The timing gets thrown off and in between readings I get some zero values. Ultimately, I would like to do a sweep with the servo when the distance is less than 2, then store the values in variables and calculate the best path to travel, but the servo is getting false triggered with the zero values. Is there something I can do to fix the timing? I have tried different clock speeds, delays, etc. but none seem to fix the problem. I have attached an image of the Blockly program. When I disable the IF blocks, the program works as intended. When I enable them, I get multiple zero values in between readings.
200.7 KB Views: 13