Guest User

Untitled

a guest
Jan 20th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. //The pin location of the sensor
  2. int hallsensor = 2; typedef struct{
  3.  
  4. //Defines the structure for multiple fans and
  5. //their dividers
  6. char fantype;
  7. unsigned int fandiv; }fanspec;
  8.  
  9. //Definitions of the fans
  10. //This is the varible used to select the fan and it's divider,
  11. //set 1 for unipole hall effect sensor
  12. //and 2 for bipole hall effect sensor
  13. fanspec fanspace[3]={{0,1},{1,2},{2,8}}; char fan = 1;
  14.  
  15. void rpm ()
  16. //This is the function that the interupt calls
  17. { NbTopsFan++; }
  18.  
  19. //This is the setup function where the serial port is initialised,
  20. //and the interrupt is attached
  21. void setup()
  22. { pinMode(hallsensor, INPUT);
  23. Serial.begin(9600);
  24. attachInterrupt(0, rpm, RISING); }
  25.  
  26. void loop ()
  27. //Set NbTops to 0 ready for calculations
  28. { NbTopsFan = 0;
  29.  
  30. //Enables interrupts
  31. sei();
  32.  
  33. //Wait 1 second
  34. delay (1000);
  35.  
  36. //Disable interrupts
  37. cli();
  38.  
  39. //Times NbTopsFan (which is apprioxiamately the fequency the fan
  40. //is spinning at) by 60 seconds before dividing by the fan's divider
  41. Calc = ((NbTopsFan * 60)/fanspace[fan].fandiv);
  42.  
  43. //Prints the number calculated above
  44. Serial.print (Calc, DEC);
  45.  
  46. //Prints " rpm" and a new line
  47. Serial.print (" rpmrn");
  48. }
Add Comment
Please, Sign In to add comment