Advertisement
mikroavr

read_flow_sensor

Mar 6th, 2019
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. volatile unsigned long cacah;
  2. float liter;
  3. const byte interruptPin = 2;
  4. unsigned long cur_time, old_time;
  5. const unsigned long interval = 500; // ambil data per 0.5 detik
  6. const unsigned calibration = 250;
  7. String txt_tampil;
  8.  
  9. void setup() {
  10.   // put your setup code here, to run once:
  11.     Serial.begin(9600);
  12.     attachInterrupt(digitalPinToInterrupt(interruptPin), flow, CHANGE);
  13. }
  14.  
  15. void loop() {
  16.   // put your main code here, to run repeatedly:
  17.     cur_time = millis();
  18.     if ( cur_time - old_time >= interval ){
  19.       liter = (float)cacah/calibration;
  20.       txt_tampil = String("Cacah: ") + cacah + " Volume: " + liter + " mL";
  21.       Serial.println(txt_tampil);
  22.       old_time = cur_time;
  23.     }
  24. }
  25.  
  26. void flow(){
  27.   cacah++;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement