munther_abdellatif

APPROX

Jun 2nd, 2020
95
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. float max=10,min=0,need =3,read=0;
  2. float x1=5,x2=0;
  3.  
  4. void setup() {Serial.begin(9600);}
  5.  
  6. void loop()
  7. {
  8.   read=0.7*x1+1;
  9.   if (read<need){
  10.     x2=(max-x1)/2+x1; min=x1; x1=x2;}
  11.   else if (read>need){
  12.     x2=(x1-min)/2+min; max=x1; x1=x2;}
  13.   Serial.print("Read value :");
  14.   Serial.print(read);
  15.   Serial.print("  set value :");
  16.   Serial.print(need);
  17.   Serial.print(" control value:");
  18.   Serial.print(x1);
  19.   Serial.print(" max :");
  20.   Serial.print(max);
  21.   Serial.print(" min :");
  22.   Serial.println(min);
  23.   delay(1000);
  24. }
RAW Paste Data