RuiViana

Velocimetro

Jul 31st, 2016
312
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <LiquidCrystal.h>
  2. LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
  3.  
  4. //#include <LiquidCrystal_I2C.h> // Biblioteca LCD I2C
  5. //LiquidCrystal_I2C lcd(0x38, 2, 1, 0, 7, 6, 5, 4, 3, POSITIVE); // Set the LCD I2C address
  6.  
  7. unsigned long temp;
  8. unsigned long temp1;
  9. float vel;
  10. const int buttonPin1 = 2;
  11. const int buttonPin2 = 3; //pino 3
  12. const int ledPin = 13; // pino 13 led
  13. int buttonState1 = 0;
  14. int buttonState2 = 0;
  15. unsigned long tempo;
  16. //------------------------------------------
  17. void setup()
  18. {
  19. lcd.begin(16, 2);
  20. pinMode(ledPin, OUTPUT); // led saida
  21. pinMode(buttonPin1, INPUT_PULLUP); // pino2, sensor 1
  22. pinMode(buttonPin2, INPUT_PULLUP); // sensor 2
  23.  
  24. Serial.begin(9600);
  25. vel = 0;
  26. temp = 0;
  27. temp1 = 0;
  28. lcd.clear();
  29. lcd.setCursor(0, 0);
  30. lcd.print("Temp = ");
  31. lcd.setCursor(0, 1);
  32. lcd.print("Veloc= ");
  33. }
  34. //-----------------------------------
  35. void loop()
  36. {
  37.  
  38. buttonState1 = digitalRead(buttonPin1);
  39. buttonState2 = digitalRead(buttonPin2);
  40. if (buttonState1 == LOW) // se o botao 1 estiver activado
  41. {
  42. digitalWrite(ledPin, HIGH);
  43. temp = millis();
  44. }
  45. if (buttonState2 == LOW)
  46. {
  47. temp1 = millis() - temp;
  48. lcd.setCursor(7, 0);
  49. lcd.print(temp1/1000);
  50. lcd.print(" ");
  51. lcd.setCursor(7, 1);
  52. vel = 30000 / (temp1 );
  53. lcd.print(vel,0);
  54. lcd.print(" m/seg ");
  55. }
  56. }
RAW Paste Data