Advertisement
dianartanto

bacakecepatananginmotordcdanoptointerrupter

Jun 22nd, 2015
1,535
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.42 KB | None | 0 0
  1. volatile int rpmcount = 0;
  2. int rpm = 0;
  3. unsigned long lastmillis = 0;
  4. void setup(){
  5.  Serial.begin(9600);
  6.  attachInterrupt(0, rpm_fan, FALLING);
  7. }
  8. void loop(){
  9.  if (millis() - lastmillis == 1000){  
  10.  detachInterrupt(0);
  11.  Serial.print(analogRead(0));
  12.  Serial.print(',');
  13.  Serial.println(rpmcount);
  14.  rpmcount = 0;
  15.  lastmillis = millis();
  16.  attachInterrupt(0, rpm_fan, FALLING);}
  17. }
  18.  
  19. void rpm_fan(){
  20.   rpmcount++;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement