Tuesday, June 7, 2022

tinkercad lcd screen

#include <LiquidCrystal.h>

char text1[] = "   Time up is";
unsigned long t;

LiquidCrystal lcd(7, 6, 5, 4, 3, 2); 

void setup()
{
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print(text1);
  
  TCCR1A = 0b00000000; //TCCR1A bit 0, 1 and TCCR1B bit 3, 4 set timer mode
  TCCR1B = 0b00001101; //Set mode to be clear on compare. set scaler to be clock/1024
  OCR1A = 15624; //period = (OCR1A/B + 1)*scaler*62.5ns = 1s
  TIMSK1 = 0b00000010; //enable timer counter
  sei();
}

void loop()
{
}

ISR(TIMER1_COMPA_vect){
t = millis();
 lcd.setCursor(0, 1);
  lcd.print("       ");
  lcd.print(t/1000);
  lcd.print("s");
}

reference:

timer

No comments:

Post a Comment