element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Arduino LCD Timer
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 14 replies
  • Subscribers 394 subscribers
  • Views 1211 views
  • Users 0 members are here
Related

Arduino LCD Timer

Former Member
Former Member over 11 years ago

Hi All,

 

I am making a model rocket launch controller, it features a safety, Arm switch, a launch button, and a 16x2 LCD display. So to launch the rocket you Arm the Rocket by flipping the arming switch. Then you turn the saftey key, which is an electronic safety. A HIGH signal is passed through the key switch, which allows the rocket to launch. here is my current code.

 

#include <LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7);


//Define Booleans
boolean Armed = true;
boolean Safe = true;
boolean DeArmedTestPassed = false;
boolean HasLaunched = false;
boolean Launch = false;
//Define Pins
int ArmPin = 8;
int SafePin = 9;
int LaunchPin = 10;
int Piezo = 11;
int Igniter = 12;
int SwitchLed = 13;
int PotPin = 0;


char * erase = "                ";


int PotVal = 0;


void setup()
{
pinMode(ArmPin, INPUT);
pinMode(SafePin, INPUT);
pinMode(PotPin, INPUT);
pinMode(LaunchPin,INPUT);
Serial.begin(9600);
lcd.begin(16,2);




    for(int i = 0; i <= 2; i++)
      {
lcd.setCursor(0,0);
lcd.println("    Welcome To    ");
lcd.setCursor(0,1);
lcd.println(" Rocket Launch 1 ");
delay(1000);
lcd.setCursor(0,1);
lcd.println(erase);
lcd.setCursor(0,0);
lcd.println(erase);
delay(1000);
      }


lcd.clear();



   for(int j = 1; j  < 3; j++) // CHANGE ME
     {
    lcd.setCursor(0,0);
    lcd.print("   Loading      "); //10
    delay(500);
    lcd.setCursor(10,0);
    lcd.print(".");
    delay(500);
    lcd.setCursor(11,0);
    lcd.print(".");
    delay(500);
    lcd.setCursor(12,0);
    lcd.print(".");
    delay(500);
     }
lcd.clear();

if(digitalRead(ArmPin) == HIGH)
  DeArmedTestPassed = false;

else if(digitalRead(ArmPin) == LOW)
DeArmedTestPassed = true;

digitalWrite(13,LOW);
}


void loop()
{

  if(DeArmedTestPassed)
      {
    PotVal = (analogRead(PotPin), 0, 1023, 0, 120); //Figure me out
    lcd.setCursor(0,0);
    delay(100);
    if(digitalRead(ArmPin) == HIGH && !HasLaunched)
        Armed = true;
    else
        Armed = false;
    if(digitalRead(SafePin) == HIGH)
        Safe = true;
    else
        Safe = false;
        if(digitalRead(LaunchPin) == HIGH)
        Launch = true;
   
    if(Armed)
      {
        lcd.setCursor(0,0);
        lcd.print("Status    Armed ");
        delay(250);
        HasLaunched = false;
      }
    else
      {
        lcd.setCursor(0,0);
        lcd.print("Status  Un-Armed");
        delay(250);
      }
    if(Safe)
      {
         lcd.setCursor(10,1);
         lcd.print(" SAFE ");
      }
    else
      {
         lcd.setCursor(10,1);
         lcd.print("      ");
      }


    if(Armed && !Safe && !HasLaunched)
    {
     lcd.setCursor(9,1);
     lcd.print("LAUNCH");
     delay(150);
     lcd.setCursor(9,1);
     lcd.print("      ");
     delay(150);
    }
   
    lcd.setCursor(0,1);
    lcd.print("T 00:00");
     }


    else if(!DeArmedTestPassed)
      {
         lcd.setCursor(0,0);
         lcd.print("Please de-arm   ");
         lcd.setCursor(0,1);
         lcd.print("device & reset");
      }
      if(Armed && !Safe && !HasLaunched &&  Launch)
      {
       lcd.setCursor(8,1);
       lcd.print("LAUNCH!");
       digitalWrite(13, HIGH);
       delay(1500);
       digitalWrite(13, LOW);
       lcd.setCursor(8,1);
       lcd.print("        ");
       Launch = false;
       Armed = false;
       HasLaunched = true;
      }
}

So here is my problem. I will have a 10k pot. And as I turn it I want the time displayed(mock up at line 140)  to increase to 2:00 when the pot is at max, and 00:05 at 0 pot. And once the system is unsafe and armed, you can initiate the launch. Once the launch is initiated it will count down and update the display to the new time every second. I have absolutely no idea how to set up the timer and display the decreasing time. I know I will have to use some form of a for loop. Bout it image

Thanks Guys,

 

Austin

  • Sign in to reply
  • Cancel

Top Replies

  • kidiccurus
    kidiccurus over 11 years ago +1
    Wow, another arduino detonator, there seem to be a lot of them at the moment. Not the answer to your question but lines 29 to 32, shouldn't at lest one pin be set as output.
  • kidiccurus
    kidiccurus over 11 years ago in reply to nschreiber0813 +1
    You rember I said there were a lot of detonators at the moment. This is what I was taking about (Noah). I also have a friend working on a simple microcontroller free version.
  • Former Member
    Former Member over 11 years ago +1
    Hey Noah, I will record a little video later showing you the progress I have made. If you want to talk about it email me at austin2118ace@gmail.com this is not the best place to discuss it. -Austin
Parents
  • Former Member
    0 Former Member over 11 years ago

    Hey Guys,

    So I have found some code I believe will work, but I need to repurpose it for my LCD, since the original code uses a 7 Segment display.

    int potPin = 0;
    int seconds = 0;
    int h = 0;
    
    
    
    
    //Format Display #:## for greater than 60 seconds
        if (seconds >= 60){
          segment.drawColon(true);
          segment.writeDigitNum(0, 0);
          segment.writeDigitNum(1, (seconds/60)); //minutes
          segment.writeDigitNum(3, (seconds % 60)/10); //tens of seconds
          segment.writeDigitNum(4, (((seconds % 60) % 10))); //seconds
          segment.writeDisplay();
        }
       
        //Format Display ##.# for less than 60 seconds but greater than 10 seconds
        if (seconds >= 10 && seconds < 60) {
          segment.drawColon(false);
          segment.writeDigitNum(0, (seconds/10));
          segment.writeDigitNum(1, (seconds % 10), true);
          segment.writeDigitNum(3,0);
          segment.writeDigitNum(4,0);
          segment.writeDisplay();
        }
        //Format Display #.## for less than 10 seconds
        if (seconds < 10) {
          segment.drawColon(false);
          segment.writeDigitNum(0, 0);
          segment.writeDigitNum(1, seconds, true);
          segment.writeDigitNum(3,0);
          segment.writeDigitNum(4,0);
          segment.writeDisplay();
        }
       
       
         //segment.println(seconds);
        //segment.writeDisplay(); 
       
        //Button
        button = digitalRead(inPin);   // read the input pin
        //Serial.println(button);
    
       delay(10);
      }
    
      if (button == 0 ){ //Code for Launch Button Pressed
        Serial.println("LAUNCH");
       
        //Play Sound
        tone(speakerPin, 700);
        delay(250);
        noTone(speakerPin);
        tone(speakerPin, 800);
        delay(250);
        noTone(speakerPin);
       
        h = seconds * 100;
       
       for (h!=0; h--;){
        
            if (h >= 6000){
              //Format Display ##:## for greater than 60sec
              segment.drawColon(true);
              segment.writeDigitNum(0, 0); //tens of minutes
              segment.writeDigitNum(1, (h/6000)); //minutes
              segment.writeDigitNum(3, ((h % 6000)/1000) % 10); //tens of seconds
              segment.writeDigitNum(4, (((h % 6000/100) % 10))); //seconds
              segment.writeDisplay();
              }
             
            //Format Display ##.## for less than 60 seconds 
            if (h < 6000) {
              segment.drawColon(false);
              segment.writeDigitNum(0,((h % 6000)/1000) % 10); //tens seconds
              segment.writeDigitNum(1, (((h % 6000/100) % 10)), true); // seconds
              segment.writeDigitNum(3,(h % 100) / 10); // tenths of seconds
              segment.writeDigitNum(4,(h % 100) % 10); // hundredths of seconds
              segment.writeDisplay();
             
           
            }
           
            //Play sound last 10 seconds
            if (h <= 1000) {
              if (h == 1000 ){
                tone(speakerPin, 800); //Play sound
              }
                if (h <= 1000 && (h % 100) / 10 == 0 && h > 50){
                tone(speakerPin, 800); //Play sound
              }
               if ((h % 100) / 10 == 8) {
                  noTone(speakerPin);}
             }
            
             //Play sound every 30 seconds (1:30, 1:00, 30.0)
           
            if (h/100 == 30 || h/100 == 60 || h/100 == 90 && (h % 100) / 10 == 8){
              tone(speakerPin, 800); //Play sound
            }
           
             if ((h % 100) / 10 == 8) {
                  noTone(speakerPin);
                }
                 
            delay(10);
        }

     

    So how would I change this code to work with a LCD, my time is wrote at 3,1 on my LCD as 00:00.

                                                                                      

    Thanks,

    Austin

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Reply
  • Former Member
    0 Former Member over 11 years ago

    Hey Guys,

    So I have found some code I believe will work, but I need to repurpose it for my LCD, since the original code uses a 7 Segment display.

    int potPin = 0;
    int seconds = 0;
    int h = 0;
    
    
    
    
    //Format Display #:## for greater than 60 seconds
        if (seconds >= 60){
          segment.drawColon(true);
          segment.writeDigitNum(0, 0);
          segment.writeDigitNum(1, (seconds/60)); //minutes
          segment.writeDigitNum(3, (seconds % 60)/10); //tens of seconds
          segment.writeDigitNum(4, (((seconds % 60) % 10))); //seconds
          segment.writeDisplay();
        }
       
        //Format Display ##.# for less than 60 seconds but greater than 10 seconds
        if (seconds >= 10 && seconds < 60) {
          segment.drawColon(false);
          segment.writeDigitNum(0, (seconds/10));
          segment.writeDigitNum(1, (seconds % 10), true);
          segment.writeDigitNum(3,0);
          segment.writeDigitNum(4,0);
          segment.writeDisplay();
        }
        //Format Display #.## for less than 10 seconds
        if (seconds < 10) {
          segment.drawColon(false);
          segment.writeDigitNum(0, 0);
          segment.writeDigitNum(1, seconds, true);
          segment.writeDigitNum(3,0);
          segment.writeDigitNum(4,0);
          segment.writeDisplay();
        }
       
       
         //segment.println(seconds);
        //segment.writeDisplay(); 
       
        //Button
        button = digitalRead(inPin);   // read the input pin
        //Serial.println(button);
    
       delay(10);
      }
    
      if (button == 0 ){ //Code for Launch Button Pressed
        Serial.println("LAUNCH");
       
        //Play Sound
        tone(speakerPin, 700);
        delay(250);
        noTone(speakerPin);
        tone(speakerPin, 800);
        delay(250);
        noTone(speakerPin);
       
        h = seconds * 100;
       
       for (h!=0; h--;){
        
            if (h >= 6000){
              //Format Display ##:## for greater than 60sec
              segment.drawColon(true);
              segment.writeDigitNum(0, 0); //tens of minutes
              segment.writeDigitNum(1, (h/6000)); //minutes
              segment.writeDigitNum(3, ((h % 6000)/1000) % 10); //tens of seconds
              segment.writeDigitNum(4, (((h % 6000/100) % 10))); //seconds
              segment.writeDisplay();
              }
             
            //Format Display ##.## for less than 60 seconds 
            if (h < 6000) {
              segment.drawColon(false);
              segment.writeDigitNum(0,((h % 6000)/1000) % 10); //tens seconds
              segment.writeDigitNum(1, (((h % 6000/100) % 10)), true); // seconds
              segment.writeDigitNum(3,(h % 100) / 10); // tenths of seconds
              segment.writeDigitNum(4,(h % 100) % 10); // hundredths of seconds
              segment.writeDisplay();
             
           
            }
           
            //Play sound last 10 seconds
            if (h <= 1000) {
              if (h == 1000 ){
                tone(speakerPin, 800); //Play sound
              }
                if (h <= 1000 && (h % 100) / 10 == 0 && h > 50){
                tone(speakerPin, 800); //Play sound
              }
               if ((h % 100) / 10 == 8) {
                  noTone(speakerPin);}
             }
            
             //Play sound every 30 seconds (1:30, 1:00, 30.0)
           
            if (h/100 == 30 || h/100 == 60 || h/100 == 90 && (h % 100) / 10 == 8){
              tone(speakerPin, 800); //Play sound
            }
           
             if ((h % 100) / 10 == 8) {
                  noTone(speakerPin);
                }
                 
            delay(10);
        }

     

    So how would I change this code to work with a LCD, my time is wrote at 3,1 on my LCD as 00:00.

                                                                                      

    Thanks,

    Austin

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
Children
No Data
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube