Things used in this project

Schematics

Schema
Lcd keypad shield diagram pinout wiring configuration schematics 0tarom0owp

Code

fm2C/C++
#include <LiquidCrystal.h>
#include "TimerOne.h"
#include <Math.h>
// select the pins used on the LCD panel
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
//time defines
unsigned long T1 = 0;
unsigned long T2 = 0;
unsigned long T3 = 0;
unsigned long Told = 1;
// define a bool value to know when the cycle is done and need to calculate
bool Cycle = false;
int reciveddata = 128;
void setup()
{
  //initiate timer1 with 1 sec delay
  Timer1.initialize(1000000);
  //add the function that will be run every 1 sec
  Timer1.attachInterrupt(thedisplayfunction);
  // enable the interrupt in rising endge
  attachInterrupt(0, isr, RISING);
  // Initialize LCD
  lcdcharinitiate();
  lcd.begin(16 , 2);
  // generate pwm signal for testing
  analogWrite(11, reciveddata);
}
void loop()
{
  //we dont need to do anything here
  //i dont like using loop and i avoid it when i can
}
void isr()
{
  // get the current time
  unsigned long now = micros();
  if (Cycle)
  {
    // if the cycle is done the get the total time
    T2 = now;
    Cycle = !Cycle;
    T3 = T2 - T1;
  }
  else
  {
    // if the cycle is not done then calculate the start of the cycle time
    T1 = now;
    Cycle = !Cycle;
  }
}
void thedisplayfunction()
{
  if (T3 != Told)
  {
    lcd.clear();
    lcdDot(10);
    lcd.setCursor(14, 1);
    lcd.print("Hz");
    double theRealValue = 1 / (((double)T3) / 1000000);
    if (isinf(theRealValue))
    {
      theRealValue = 0;
    }
    String theStringValue = String(theRealValue);
    int theStringLenght = theStringValue.length();
    int p = 13;
    for (int i = theStringLenght ; i >= 0 ; i--)
    {
      int thenum = (int)theStringValue[i] - 48;
      numberprinter(thenum, p);
      p--;
    }
    Told = T3;
  }
}
//find the needed characer and added it to the needed position
void numberprinter(int num , int pos)
{
  if (num == 0)
  {
    lcdnumber0(pos);
  }
  if (num == 1)
  {
    lcdnumber1(pos);
  }
  if (num == 2)
  {
    lcdnumber2(pos);
  }
  if (num == 3)
  {
    lcdnumber3(pos);
  }
  if (num == 4)
  {
    lcdnumber4(pos);
  }
  if (num == 5)
  {
    lcdnumber5(pos);
  }
  if (num == 6)
  {
    lcdnumber6(pos);
  }
  if (num == 7)
  {
    lcdnumber7(pos);
  }
  if (num == 8)
  {
    lcdnumber8(pos);
  }
  if (num == 9)
  {
    lcdnumber9(pos);
  }
}
//initiate the lcd custom charcters
void lcdcharinitiate()
{
  //number 0 charaters 2x2 decimals
  byte C0[8] = {0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02};
  byte C1[8] = {0x0E, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x0E};
  byte C2[8] = {0x0E, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0E};
  byte C3[8] = {0x0E, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0E};
  byte C5[8] = {0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0E};
  byte C4[8] = {0x0E, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A, 0x0A};
  byte C6[8] = {0x0E, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02};
  byte C7[8] = {0x18, 0x18, 0x18, 0x18, 0x18, 0x1E, 0x1F, 0x1F};

  lcd.createChar(0 , C0);
  lcd.createChar(1 , C1);
  lcd.createChar(2 , C2);
  lcd.createChar(3 , C3);
  lcd.createChar(4 , C4);
  lcd.createChar(5 , C5);
  lcd.createChar(6 , C6);
  lcd.createChar(7 , C7);
  lcd.begin(16 , 2);
}
//lcd draw character functions
void lcdnumber0(int startposition)
{
  lcd.setCursor(startposition + 0, 0);
  lcd.write(byte(4));
  lcd.setCursor(startposition + 0, 1);
  lcd.write(byte(5));
}
void lcdnumber1(int startposition)
{
  lcd.setCursor(startposition + 0, 0);
  lcd.write(byte(0));
  lcd.setCursor(startposition + 0, 1);
  lcd.write(byte(0));
}
void lcdnumber2(int startposition)
{
  lcd.setCursor(startposition + 0, 0);
  lcd.write(byte(1));
  lcd.setCursor(startposition + 0, 1);
  lcd.write(byte(2));
}
void lcdnumber3(int startposition)
{
  lcd.setCursor(startposition + 0, 0);
  lcd.write(byte(1));
  lcd.setCursor(startposition + 0, 1);
  lcd.write(byte(1));
}
void lcdnumber4(int startposition)
{
  lcd.setCursor(startposition + 0, 0);
  lcd.write(byte(5));
  lcd.setCursor(startposition + 0, 1);
  lcd.write(byte(6));
}
void lcdnumber5(int startposition)
{
  lcd.setCursor(startposition + 0, 0);
  lcd.write(byte(2));
  lcd.setCursor(startposition + 0, 1);
  lcd.write(byte(1));
}
void lcdnumber6(int startposition)
{
  lcd.setCursor(startposition + 0, 0);
  lcd.write(byte(2));
  lcd.setCursor(startposition + 0, 1);
  lcd.write(byte(3));
}
void lcdnumber7(int startposition)
{
  lcd.setCursor(startposition + 0, 0);
  lcd.write(byte(6));
  lcd.setCursor(startposition + 0, 1);
  lcd.write(byte(0));
}
void lcdnumber8(int startposition)
{
  lcd.setCursor(startposition + 0, 0);
  lcd.write(byte(3));
  lcd.setCursor(startposition + 0, 1);
  lcd.write(byte(3));
}
void lcdnumber9(int startposition)
{
  lcd.setCursor(startposition + 0, 0);
  lcd.write(byte(3));
  lcd.setCursor(startposition + 0, 1);
  lcd.write(byte(1));
}

void lcdDot(int startposition)
{
  lcd.setCursor(startposition + 0, 1);
  lcd.write(byte(165));
}

Credits

Antu arduino icon small svg iwumdlklvy
Arduino World

15 Years Embedded System Programming and Development Experience

Contact

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Direction Indicators for Bikes
Intermediate
  • 131
  • 5

Full instructions

Riding bike is a little dangerous. With the Direction Indicators for a bike, car's know if you want to turn right or left. Make biking safe!

Starry Night Prom
Intermediate
  • 997
  • 7

How did I stand out at prom? In a light up dress of course!

The Trump Button
Intermediate
  • 787
  • 7

Full instructions

The famous connected button to order your favorite drink using Sigfox network.

ArduRadio AlarmClock
Intermediate
  • 1,432
  • 2

Full instructions

Build an FM radio with alarm clock.

Third Eye for The Blind
Intermediate
  • 673
  • 10

Full instructions

An innovative wearable technology for visually impaired peoples.

One Button Restart of a Stalled Raspberry Pi Zero W
Intermediate
  • 2,110
  • 15

Full instructions

Avoid SD card corruption on a non-responsive RPi using an Arduino to log into the serial console and restart your RPi from the root account.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login