Advertisement
nikolas77

tachometer

Oct 5th, 2020
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Adafruit_GFX.h>
  2. #include <MCUFRIEND_kbv.h>
  3. MCUFRIEND_kbv tft;
  4.  
  5. #define BLACK           0x0000                                                                                              
  6. #define LIGHTBLUE       0x34DF
  7. #define BLUE            0x001F
  8. #define VERYDARKBLUE    0x0005
  9. #define LIGHTRED        0xF945
  10. #define RED             0xF800
  11. #define DARKRED         0x8800
  12. #define VERYDARKRED     0x3800
  13. #define GREEN           0x07E0
  14. #define VERYDARKGREEN   0x0140
  15. #define KHAKIGREEN      0x195B62
  16. #define CYAN            0x07FF
  17. #define VERYDARKCYAN    0x0145
  18. #define MAGENTA         0xF81F
  19. #define VERYDARKMAGENTA 0x3803
  20. #define YELLOW          0xFFE0
  21. #define VERYDARKYELLOW  0x3180
  22. #define WHITE           0xFFFF
  23. #define VERYDARKGRAY    0x2124
  24. #define GRAY            0xA514
  25. #define ORANGE          0xFC21
  26. #define VERYDARKORANGE  0x4920
  27.  
  28. uint16_t g_identifier;                                                                                        
  29. uint8_t OrientationTFT = 1;
  30.  
  31. float value=0;
  32. float rev=0;
  33. int rpm;
  34. int oldtime=0;
  35. int time;
  36.  
  37. void isr()
  38. {
  39. rev++;
  40. }
  41.  
  42. void setup()
  43. {
  44.     tft.begin(9600);                                                                                                          
  45.     tft.reset();                                                                                                  
  46.     g_identifier = tft.readID();                                                                                          
  47.     tft.begin(g_identifier);                                                                                                
  48.  
  49.     tft.fillScreen(BLACK);                                                                                                
  50.     tft.setRotation(OrientationTFT);
  51.    
  52.     attachInterrupt(0,isr,RISING);
  53. }
  54.  
  55. void loop()
  56. {
  57.     delay(1000);
  58.     detachInterrupt(0);  
  59.     time=millis()-oldtime;  
  60.     rpm=(rev/time)*60000;    
  61.     oldtime=millis();          
  62.     rev=0;
  63.    
  64.     tft.setTextColor(LIGHTBLUE , BLACK);                        
  65.     tft.setCursor(5, 5);
  66.     tft.setTextSize(4);
  67.     tft.print("___TACHOMETER___");
  68.     tft.setCursor(5,50);
  69.     tft.print(     rpm);
  70.     tft.setCursor(60,50);
  71.     tft.print(" RPM");
  72.    
  73.     attachInterrupt(0,isr,RISING);
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement