Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- volatile unsigned long cacah;
- float liter;
- const byte interruptPin = 2;
- unsigned long cur_time, old_time;
- const unsigned long interval = 500; // ambil data per 0.5 detik
- const unsigned calibration = 250;
- String txt_tampil;
- void setup() {
- // put your setup code here, to run once:
- Serial.begin(9600);
- attachInterrupt(digitalPinToInterrupt(interruptPin), flow, CHANGE);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- cur_time = millis();
- if ( cur_time - old_time >= interval ){
- liter = (float)cacah/calibration;
- txt_tampil = String("Cacah: ") + cacah + " Volume: " + liter + " mL";
- Serial.println(txt_tampil);
- old_time = cur_time;
- }
- }
- void flow(){
- cacah++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement