I am using Arduino, Esp8266(with uart), HX711 and servo motors. I did this project with Raspberry pi pico on micropython but there is not much library on micropython so i decided to go with Arduino. I make everything work with arduino but i couldn't find async work. I found something with millis() function but it's not waiting at all.What i want is My http response need to come first then servo need to go 0 degree then HX711 should measure weight until 500 gram then servo need to go 90 degree.Now loop should start again with http response.Here is my while loop. I am using this for measure weight HX711_ADC/examples/Read_1x_load_cell at master · olkal/HX711_ADC · GitHub .
unsigned long StartTime_HTTP=0; // variables
unsigned long interval_HTTP=750; //
unsigned long StartTime_Servo1=25; //
unsigned long interval_Servo1=1000; //
unsigned long StartTime_HX711=50; //
unsigned long interval_HX711=1250; //
void loop() {
static boolean newDataReady = 0;
const int serialPrintInterval = 0;
if (LoadCell.update()) newDataReady = true;
if (newDataReady) {
float i = LoadCell.getData();
Serial.println(i);
newDataReady = 0;
unsigned currentTime=millis();
if(currentTime-StartTime_HTTP>=interval_HTTP){
StartTime_HTTP=currentTime;
http.Get("https://example.example.com/headers/"); // i wrote function for http.Get
}
if(currentTime-StartTime_Servo1>=interval_Servo1){
StartTime_Servo1=currentTime;
servo1.write(0);
}
if(currentTime-StartTime_HX711>=interval_HX711){
StartTime_HX711=currentTime;
if(i>400){
Serial.println(i);
servo1.write(90);
}
}
}
}
}
When i run this code , http response working again and again , this code not working async and if(i>400) line is working 1 time then not working. What i want is My http response need to come first then servo need to go 0 degree then HX711 should measure weight until 500 gram then servo need to go 90 degree.Now loop should start again with http response.Is there a way that i could make async this code ? Thanks for helping.