Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // include the library code:
- #include <LiquidCrystal.h>
- // initialize the library with the numbers of the interface pins
- LiquidCrystal lcd(12, 11, 7, 6, 5, 4);
- volatile unsigned long firstPulseTime;
- volatile unsigned long lastPulseTime;
- volatile unsigned long numPulses;
- void isr()
- {
- unsigned long now = micros();
- if (numPulses == 1)
- {
- firstPulseTime = now;
- }
- else
- {
- lastPulseTime = now;
- }
- ++numPulses;
- }
- void setup() {
- Serial.begin(9600);
- // set up the LCD's number of columns and rows:
- lcd.begin(16, 2);
- // Print a message to the LCD.
- lcd.setCursor(0, 0);
- lcd.print("Freq [Hz]:");
- lcd.setCursor(0, 1);
- lcd.print("Vel [m/s]:");
- //pinMode(3, OUTPUT); // put a PWM signal on pin 3, then we can connect pin 3 to pin 2 to test the counter
- //analogWrite(3, 128);
- }
- // Measure the frequency over the specified sample time in milliseconds, returning the frequency in Hz
- float readFrequency(unsigned int sampleTime)
- {
- numPulses = 0; // prime the system to start a new reading
- attachInterrupt(0, isr, RISING); // enable the interrupt
- delay(sampleTime);
- detachInterrupt(0);
- return (numPulses < 3) ? 0 : (1000000.0 * (float)(numPulses - 2))/(float)(lastPulseTime - firstPulseTime);
- }
- void loop() {
- float freq = readFrequency(1000);
- int rssi = analogRead(3);
- //float freq = 5;
- float vel = 0.01424 * freq;
- // set the cursor to column 0, line 1
- // (note: line 1 is the second row, since counting begins with 0):
- lcd.setCursor(11, 1);
- // print the number of seconds since reset:
- lcd.print(vel);
- lcd.setCursor(11, 0);
- // print the number of seconds since reset:
- lcd.print(freq);
- Serial.print(millis());
- Serial.print(",");
- Serial.print(freq);
- Serial.print(",");
- Serial.print(vel);
- Serial.print(",");
- Serial.println(rssi);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement