Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.08 KB | None | 0 0
  1. #include <LiquidCrystal.h>
  2.  
  3. // LCD display pins
  4. LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
  5.  
  6. // variables
  7. long impulses, time, previous, tripTime;
  8. unsigned long previousImpulse = 0, currentImpulse, timeBetweenImpulses;
  9. float currentSpeed, dist, averageSpeed, totalDistance;
  10. float circuit = 0.4396; // wheel circuit in meters
  11. int screen;
  12.  
  13. void Lcd() {
  14.     lcd.setCursor(0, 0);
  15.     lcd.print("Spd: ");
  16.     lcd.setCursor(0, 1);
  17.     lcd.print("Dist: ");
  18.     lcd.setCursor(5, 0);
  19.     lcd.print(currentSpeed);
  20.     lcd.setCursor(11, 0);
  21.     lcd.print(" cm/m");
  22.     dist = impulses*circuit; // distance in meters
  23.     lcd.setCursor(6, 1);
  24.     lcd.print(dist);
  25.     lcd.setCursor(14, 1);
  26.     lcd.print(" m");
  27.  }
  28. //void Lcd();
  29.  
  30. void setup() {
  31.   lcd.begin(16, 2); //Deklaracja typu
  32.  
  33.   pinMode(A0, INPUT);
  34. }
  35.  
  36. void loop() {
  37.   if(analogRead(A0)>=70) {
  38.       impulses++;
  39.       time = (millis()-previous);
  40.       currentSpeed = (circuit/time)*60000.0; // speed in meters per minute
  41.       previous = millis();
  42.       //previousImpulse = currentImpulse;
  43.       Lcd();
  44.       delay(100);
  45.   }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement