Guest User

Untitled

a guest
Jul 1st, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.12 KB | None | 0 0
  1. // GLAVNI ARDUINO
  2.         int a = Serial.read();
  3.  
  4.         display.setCursor(SCR_SPEED_X, SCR_SPEED_Y);
  5.         display.setTextSize(1);            
  6.         display.print(a);
  7.  
  8.         // UPDATE THE TAHOMETER
  9.         display.fillRect(SCR_BRAKE_X, SCR_BRAKE_Y, SCR_BRAKE_W, 64, WHITE);
  10.         display.fillRect(SCR_BRAKE_X, SCR_BRAKE_Y, SCR_BRAKE_W, 64 - map(a, 0, 150, 0, 64), BLACK);
  11.  
  12.         refreshScreen = true;
  13.  
  14.  
  15.  
  16. // SPOREDNI ARDUINO
  17.  
  18. // PINS
  19. #define PIN_RPM_SENSOR                                                          3 // INTERRUPT PIN! DO NOT CHANGE IT!!
  20.  
  21.  
  22. // GLOBAL VARIABLES
  23. volatile uint32_t revDuration                   =                               60000;
  24. volatile uint32_t revTick                       =                               0;
  25.  
  26.  
  27. void revolution()
  28. {
  29.     revDuration = millis() - revTick;
  30.     revTick = millis();    
  31. }
  32.  
  33.  
  34. void setup()
  35. {
  36.     Serial.begin(9600);
  37.  
  38.     pinMode(PIN_RPM_SENSOR, INPUT);
  39.     attachInterrupt(digitalPinToInterrupt(PIN_RPM_SENSOR), revolution, RISING); // INTERRUPT PIN 3
  40. }
  41.  
  42.  
  43. void loop()
  44. {
  45.    Serial.write(60000 / revDuration);
  46.  
  47.     delay(500);
  48. }
Advertisement
Add Comment
Please, Sign In to add comment