Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
- //#include <LiquidCrystal_I2C.h> // Biblioteca LCD I2C
- //LiquidCrystal_I2C lcd(0x38, 2, 1, 0, 7, 6, 5, 4, 3, POSITIVE); // Set the LCD I2C address
- unsigned long temp;
- unsigned long temp1;
- float vel;
- const int buttonPin1 = 2;
- const int buttonPin2 = 3; //pino 3
- const int ledPin = 13; // pino 13 led
- int buttonState1 = 0;
- int buttonState2 = 0;
- unsigned long tempo;
- //------------------------------------------
- void setup()
- {
- lcd.begin(16, 2);
- pinMode(ledPin, OUTPUT); // led saida
- pinMode(buttonPin1, INPUT_PULLUP); // pino2, sensor 1
- pinMode(buttonPin2, INPUT_PULLUP); // sensor 2
- Serial.begin(9600);
- vel = 0;
- temp = 0;
- temp1 = 0;
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Temp = ");
- lcd.setCursor(0, 1);
- lcd.print("Veloc= ");
- }
- //-----------------------------------
- void loop()
- {
- buttonState1 = digitalRead(buttonPin1);
- buttonState2 = digitalRead(buttonPin2);
- if (buttonState1 == LOW) // se o botao 1 estiver activado
- {
- digitalWrite(ledPin, HIGH);
- temp = millis();
- }
- if (buttonState2 == LOW)
- {
- temp1 = millis() - temp;
- lcd.setCursor(7, 0);
- lcd.print(temp1/1000);
- lcd.print(" ");
- lcd.setCursor(7, 1);
- vel = 30000 / (temp1 );
- lcd.print(vel,0);
- lcd.print(" m/seg ");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement