Adding Startup Message

hi there I’m quite new to arduino an I was wondering if anyone could help, I have a code for a bike speedometer which uses a 16x2 LCD display, I wanted to add a startup message so when the device is turned on it would say “Henrys Bike” for 10 seconds and then run the code.
would anyone be able to modify the code for me?
Thanks for your time :slight_smile:

#include <LiquidCrystal.h>
LiquidCrystal lcd(13,12,11,10,9,8);









#define reed A0//pin connected to read switch


//storage variables
float radius = 13.5;// tire radius (in inches)- CHANGE THIS FOR YOUR OWN BIKE
int buttonInt=0;
int mode1=1;
int mode2=2;
int mode3=3;
volatile int selectedmode=mode1;
volatile int nselectedmode1=mode2;
volatile int nselectedmode2=mode3;
int reedVal;
long timer = 0;
float mph = 0.00;
float distance=0.00;
float circumference;
boolean backlight;


int maxReedCounter = 100;
int reedCounter;

void setup(){
  
  reedCounter = maxReedCounter;
  circumference = 2*3.14*radius;
  pinMode(1,OUTPUT);
  pinMode(2,INPUT);
  pinMode(reed, INPUT);
  lcd.begin(16,2);
  attachInterrupt(buttonInt,swap,RISING);
  Serial.write(12);

  
  

  cli();


  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1  = 0;
  
  OCR1A = 1999;// = (1/1000) / ((1/(16*10^6))*8) - 1
  
  TCCR1B |= (1 << WGM12);
  
  TCCR1B |= (1 << CS11);   
  
  TIMSK1 |= (1 << OCIE1A);
  
  sei();//allow interrupts
  //END TIMER SETUP

  Serial.begin(9600);
} 

void swap()
{
  if(selectedmode==mode1)
  {
  selectedmode=mode2;
  nselectedmode1=mode3;
  nselectedmode2=mode1;
  }
  else if(selectedmode==mode2)
  {
  selectedmode=mode3;
  nselectedmode1=mode1;
  nselectedmode2=mode2;
  }
  else
  {
  selectedmode=mode1;
  nselectedmode1=mode2;
  nselectedmode2=mode3;
  }    
}  
  
  


ISR(TIMER1_COMPA_vect) {//Interrupt at freq of 1kHz to measure reed switch
  reedVal = digitalRead(reed);//get val of A0
  if (reedVal){//if reed switch is closed
    if (reedCounter == 0){//min time between pulses has passed
      mph = (56.8*float(circumference))/float(timer);//calculate miles per hour
      timer = 0;//reset timer
      reedCounter = maxReedCounter;//reset reedCounter
    }
    else{
      if (reedCounter > 0){//don't let reedCounter go negative
        reedCounter -= 1;//decrement reedCounter
      }
    }
  }
  else{//if reed switch is open
    if (reedCounter > 0){//don't let reedCounter go negative
      reedCounter -= 1;//decrement reedCounter
    }
  }
  if (timer > 2000){
    mph = 0;//if no new pulses from reed switch- tire is still, set mph to 0
  }
  else{
    timer += 1;//increment timer
  } 
 if(digitalRead(2)==LOW)
 {
 distance +=mph;
 }
 else
 {distance=0;
 }
 
}


void displayMPH(){
  Serial.write(12);//clear
  Serial.write("Speed =");
  Serial.write(13);//start a new line
  Serial.println(mph);
  Serial.write(" MPH ");
  //Serial.write("0.00 MPH ");
}

void loop(){
  //print mph once a second
  displayMPH();
 if(selectedmode==mode1)
 { 
  lcd.setCursor(0,0);
  lcd.print("                ");
  lcd.setCursor(0,1);
  lcd.print("                ");
  lcd.setCursor(0,0);
  lcd.print("Speed=");
  lcd.setCursor(6,0);
  lcd.print(mph);
  lcd.setCursor(0,1);
  lcd.print("Distance=");
  lcd.setCursor(10,1);
  lcd.print(distance/3600000);
 }
 else if(selectedmode==mode2)
 {
  float check1=20;
  float distA=distance/3600000;
  float percent=distA/check1;
  float percent1 =percent*100;
  lcd.setCursor(0,0);
  lcd.print("                ");
  lcd.setCursor(0,1);
  lcd.print("                ");
  lcd.setCursor(0,0);
  lcd.print("Cover ");
  lcd.setCursor(6,0);
  lcd.print(check1);
  lcd.setCursor(9,0);
  lcd.print("miles");
  if(distA<check1)
  {
  lcd.setCursor(0,1);
  lcd.print("                ");
  lcd.setCursor(0,1);
  lcd.print("% complete=");
  lcd.setCursor(12,1);
  lcd.print(percent1);
  }
  else
  {
  lcd.setCursor(0,0);
  lcd.print("                ");
  lcd.setCursor(0,1);
  lcd.print("                "); 
  lcd.setCursor(0,0);
  lcd.print("Congratulations");
  lcd.setCursor(0,1);
  lcd.print("You pass");  
  }   
} 
  
     
 else
 {
  lcd.setCursor(0,0);
  lcd.print("                ");
  lcd.setCursor(0,1);
  lcd.print("                ");
  lcd.setCursor(0,0);
  lcd.print("Cover 30mph"); 
  if(mph<30)
  {
  lcd.setCursor(0,1);
  lcd.print("                ");
  lcd.setCursor(0,1);
  lcd.print("speed=");
  lcd.setCursor(6,1);
  lcd.print(mph);
  }
  else
  {
  lcd.setCursor(0,0);
  lcd.print("                ");
  lcd.setCursor(0,1);
  lcd.print("                "); 
  lcd.setCursor(0,0);
  lcd.print("Congratulations");
  lcd.setCursor(0,1);
  lcd.print("Light Rider");  
  } 
 } 
}

as its just used one time and its based on time just add the the lcd.print line to setup followed by a delay.

(make sure lcd.begin is before the print)

I wanted to add a startup message so when the device is turned on it would say “Henrys Bike” for 10 seconds and then run the code.

Permission granted. Did you have a question?

PaulS:
Permission granted. Did you have a question?

yes could you tell me what code to put in so it would display a message on startup

gpop1:
as its just used one time and its based on time just add the the lcd.print line to setup followed by a delay.

(make sure lcd.begin is before the print)

ok thanks :slight_smile: sorry I’m a complete beginner so would it be something like

LCD.begin
LCD.print Henrys Bike
Delay

henryp:
yes could you tell me what code to put in so it would display a message on startup

Normally we frown upon giving advice based on snippets of code but your requirements sound simple, so please post your code up to and including the end of the setup() function and I am sure that help will be forthcoming.

UKHeliBob:
Normally we frown upon giving advice based on snippets of code but your requirements sound simple, so please post your code up to and including the end of the setup() function and I am sure that help will be forthcoming.

Thank you so much !

#include <LiquidCrystal.h>
LiquidCrystal lcd(13,12,11,10,9,8);









#define reed A0//pin connected to read switch


//storage variables
float radius = 13.5;// tire radius (in inches)- CHANGE THIS FOR YOUR OWN BIKE
int buttonInt=0;
int mode1=1;
int mode2=2;
int mode3=3;
volatile int selectedmode=mode1;
volatile int nselectedmode1=mode2;
volatile int nselectedmode2=mode3;
int reedVal;
long timer = 0;
float mph = 0.00;
float distance=0.00;
float circumference;
boolean backlight;


int maxReedCounter = 100;
int reedCounter;

void setup(){
  
  reedCounter = maxReedCounter;
  circumference = 2*3.14*radius;
  pinMode(1,OUTPUT);
  pinMode(2,INPUT);
  pinMode(reed, INPUT);
  lcd.begin(16,2);
  attachInterrupt(buttonInt,swap,RISING);
  Serial.write(12);

  
  

  cli();


  TCCR1A = 0;
  TCCR1B = 0;
  TCNT1  = 0;
  
  OCR1A = 1999;// = (1/1000) / ((1/(16*10^6))*8) - 1
  
  TCCR1B |= (1 << WGM12);
  
  TCCR1B |= (1 << CS11);   
  
  TIMSK1 |= (1 << OCIE1A);
  
  sei();//allow interrupts
  //END TIMER SETUP

  Serial.begin(9600);
} 

void swap()
{
  if(selectedmode==mode1)
  {
  selectedmode=mode2;
  nselectedmode1=mode3;
  nselectedmode2=mode1;
  }
  else if(selectedmode==mode2)
  {
  selectedmode=mode3;
  nselectedmode1=mode1;
  nselectedmode2=mode2;
  }
  else
  {
  selectedmode=mode1;
  nselectedmode1=mode2;
  nselectedmode2=mode3;
  }    
}  
  
  


ISR(TIMER1_COMPA_vect) {//Interrupt at freq of 1kHz to measure reed switch
  reedVal = digitalRead(reed);//get val of A0
  if (reedVal){//if reed switch is closed
    if (reedCounter == 0){//min time between pulses has passed
      mph = (56.8*float(circumference))/float(timer);//calculate miles per hour
      timer = 0;//reset timer
      reedCounter = maxReedCounter;//reset reedCounter
    }
    else{
      if (reedCounter > 0){//don't let reedCounter go negative
        reedCounter -= 1;//decrement reedCounter
      }
    }
  }
  else{//if reed switch is open
    if (reedCounter > 0){//don't let reedCounter go negative
      reedCounter -= 1;//decrement reedCounter
    }
  }
  if (timer > 2000){
    mph = 0;//if no new pulses from reed switch- tire is still, set mph to 0
  }
  else{
    timer += 1;//increment timer
  } 
 if(digitalRead(2)==LOW)
 {
 distance +=mph;
 }
 else
 {distance=0;
 }
 
}


void displayMPH(){
  Serial.write(12);//clear
  Serial.write("Speed =");
  Serial.write(13);//start a new line
  Serial.println(mph);
  Serial.write(" MPH ");
  //Serial.write("0.00 MPH ");
}

void loop(){
  //print mph once a second
  displayMPH();
 if(selectedmode==mode1)
 { 
  lcd.setCursor(0,0);
  lcd.print("                ");
  lcd.setCursor(0,1);
  lcd.print("                ");
  lcd.setCursor(0,0);
  lcd.print("Speed=");
  lcd.setCursor(6,0);
  lcd.print(mph);
  lcd.setCursor(0,1);
  lcd.print("Distance=");
  lcd.setCursor(10,1);
  lcd.print(distance/3600000);
 }
 else if(selectedmode==mode2)
 {
  float check1=20;
  float distA=distance/3600000;
  float percent=distA/check1;
  float percent1 =percent*100;
  lcd.setCursor(0,0);
  lcd.print("                ");
  lcd.setCursor(0,1);
  lcd.print("                ");
  lcd.setCursor(0,0);
  lcd.print("Cover ");
  lcd.setCursor(6,0);
  lcd.print(check1);
  lcd.setCursor(9,0);
  lcd.print("miles");
  if(distA<check1)
  {
  lcd.setCursor(0,1);
  lcd.print("                ");
  lcd.setCursor(0,1);
  lcd.print("% complete=");
  lcd.setCursor(12,1);
  lcd.print(percent1);
  }
  else
  {
  lcd.setCursor(0,0);
  lcd.print("                ");
  lcd.setCursor(0,1);
  lcd.print("                "); 
  lcd.setCursor(0,0);
  lcd.print("Congratulations");
  lcd.setCursor(0,1);
  lcd.print("You pass");  
  }   
} 
  
     
 else
 {
  lcd.setCursor(0,0);
  lcd.print("                ");
  lcd.setCursor(0,1);
  lcd.print("                ");
  lcd.setCursor(0,0);
  lcd.print("Cover 30mph"); 
  if(mph<30)
  {
  lcd.setCursor(0,1);
  lcd.print("                ");
  lcd.setCursor(0,1);
  lcd.print("speed=");
  lcd.setCursor(6,1);
  lcd.print(mph);
  }
  else
  {
  lcd.setCursor(0,0);
  lcd.print("                ");
  lcd.setCursor(0,1);
  lcd.print("                "); 
  lcd.setCursor(0,0);
  lcd.print("Congratulations");
  lcd.setCursor(0,1);
  lcd.print("Light Rider");  
  } 
 } 
}

Please provide the code you wrote and we’ll

Code will vary depending if you are using the “standard” LCD interface (parallel lines) or use an I2C interface
Regardless of which one you are, it is assumed you have installed the corresponding library.
Most (if not all) LCD libraries do include an example sketch, tyically a “Hello World” example.
It is definitely assumed you have given this is shot … this is a full proof working recipe that should work right off the bat
:slight_smile:

I am sure you are familiar with the the “blink” sketch in the example sketches included with the Arduino IDE ?
(Once again, it is definitely assumed you have done so…).

Please look at the code (and look at the comments for the “void setup()” function and for the “void loop()” function.
Given the fact that “void setup()” runs only ONCE after the Arduino board is reset, this is where you should insert your “Henry’s Bike” print message …

Next time, please provide the details as to what you have done already and what kind of LCD you are using.
(When providing your code, be sure to use the code tags, as explained at http://forum.arduino.cc/index.php/topic,148850.0.html

There are plethoras of examples and Instructables on the Internet to drive an LCD.

“Google is your friend”…

dan

thanks dan I've now included the code in the original post - the LCD is a 16x2. I was using this project but I wanted to slightly change the code to add a startup message

I am far from being an expert, but I would suggest inserting the following at the very end of the void setup() function and see what it does... These should be the very last lines of the setup() function

lcd.print("Light Rider");
delay(5000);

dan