Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal_I2C.h>
- #include <Wire.h>
- #include <DS3231.h>
- #include "PinChangeInterrupt.h"
- #define BACKLIGHT_PIN 3
- int LCD1Address = 0x26;
- int LCD2Address = 0x27;
- int RTCAddress = 0x57;
- LiquidCrystal_I2C lcd1(LCD1Address, 2, 1, 0, 4, 5, 6, 7);
- LiquidCrystal_I2C lcd2(LCD2Address, 2, 1, 0, 4, 5, 6, 7);
- DS3231 rtc(SDA, SCL);
- volatile static float vss_pulse_distance = 0.0003816033;
- volatile static float unleadedFlow = 1743e-11;
- volatile unsigned long vss_pulses;
- volatile float speed;
- int vss_pin = 2;
- void setup()
- {
- Wire.begin();
- rtc.begin();
- lcd_begin();
- pinMode(vss_pin, INPUT);
- noInterrupts();
- // set and initialize the TIMER1
- TCCR1A = 0; // set entire TCCR1A register to 0
- TCCR1B = 0; // set entire TCCR1B register to 0
- TCCR1B |= (1 << CS12);
- TIMSK1 |= (1 << TOIE1);
- TCNT1 = 3036;
- interrupts();
- delay(10);
- attachInterrupt(digitalPinToInterrupt(vss_pin), distance, RISING);
- }
- void loop()
- {
- lcd1.home();
- lcd1.print("RTC - TESTBENCH1");
- lcd1.setCursor ( 0, 1 );
- lcd1.print(rtc.getTimeStr());
- lcd2.home();
- lcd2.print("SPEED - TB2");
- lcd2.setCursor ( 0, 1 );
- lcd2.print(speed);
- delay(1000);
- Serial.print(speed);
- Serial.print('\n');
- }
- void lcd_begin()
- {
- lcd1.begin(16, 2);
- lcd1.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
- lcd1.setBacklight(HIGH);
- lcd1.home ();
- lcd2.begin(16, 2);
- lcd2.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
- lcd2.setBacklight(HIGH);
- lcd2.home ();
- }
- void instantSpeed()
- {
- speed = (vss_pulse_distance * vss_pulses * 3600);
- }
- ISR(TIMER1_OVF_vect) //TIMER1 overflow interrupt -- occurs every 1sec --
- {
- instantSpeed();
- vss_pulses = 0;
- TCNT1 = 3036;
- }
- void distance()
- {
- vss_pulses++; // we calculate 3 times the same thing in order to reset the distance, the average cons. and average speed independently
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement