Results 1 to 3 of 3
  1. #1
    Wii U Section Moderator
    Computer Engineer
    MrOwnership's Avatar

    Badge

    Join Date
    Jun 2011
    Location
    Maryland
    Posts
    1,435
    Points
    2,862
         User Info     Contact     Gamer ID
    Join Date
    Jun 2011
    Location
    Maryland
    Posts
    1,435
    Points
    2,862
    Gamer IDs

    Steam ID: MrOwnership Wii Code: MrOwnership

    Default Stopwatch using an Arduino Uno

    I have been bored over the past couple days so I decided to make a stopwatch using my Arduino Uno and my 20x4 character LCD. Here are a few pictures of my circuit and a video of how it works. The video quality isn't that great as I was recording it on my phone.






    Here is my code. Its a bit sloppy, I am going to fix it up tomorrow. The lap functions don't fully work properly so I still need to fix those up.

    Code:
    // include the library code:
    #include <LiquidCrystal.h>
    
    // initialize the library with the numbers of the interface pins
    LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
    //buttons
    int startButton = 2;
    int stopButton = 3;
    int lapButton = 4;
    int resetButton = 5;
    int speedUpButton = 6;
    int normalSpeedButton = 13;
    //times
    int tenHour = 0;
    int hour = 0;
    int tenMinute = 0;
    int minute = 0;
    int tenSecond = 0;
    int second = 0;
    //Lap times
    int lTenHour = 0;
    int lHour = 0;
    int lTenMinute = 0;
    int lMinute = 0;
    int lTenSecond = 0;
    int lSecond = 0;
    //last lap times
    int lLTenHour = 0;
    int lLHour = 0;
    int lLTenMinute = 0;
    int lLMinute = 0;
    int lLTenSecond = 0;
    int lLSecond = 0;
    //other
    int milli = 1000;
    int speedTime = 1000;
    int lapAllowed = 1;
    
    void setup() {
      pinMode(startButton, INPUT_PULLUP);
      pinMode(stopButton, INPUT_PULLUP);
      pinMode(lapButton, INPUT_PULLUP);
      pinMode(resetButton, INPUT_PULLUP);
      pinMode(speedUpButton, INPUT_PULLUP);
      pinMode(normalSpeedButton, INPUT_PULLUP);
      // set up the LCD's number of columns and rows: 
      lcd.begin(20, 4);
      // Print a message to the LCD.
      lcd.setCursor(0, 0);
      lcd.print("Timer:      00:00:00");
      lcd.setCursor(0, 1);
      lcd.print("Lap:        00:00:00");
      lcd.setCursor(0, 2);
      lcd.print("Last:       00:00:00");
      lcd.setCursor(0, 3);
      lcd.print("MrOwnership's Timer ");
    }
    
    void loop() {
      if (digitalRead(startButton) == LOW){
        startLogic();
      }
      if (digitalRead(stopButton) == LOW){
        stopLogic();
      }
      if (digitalRead(lapButton) == LOW){
        lapLogic();
      }
      if (digitalRead(resetButton) == LOW){
        resetTime();
      }
      if (digitalRead(speedUpButton) == LOW){
        speedUp();
      }
      if (digitalRead(normalSpeedButton) == LOW){
        normalSpeed();
      }
      if(milli >= speedTime){
        milli = 0;
        if (second > 9){
          tenSecond++;
          second = 0;
          writeTenSecond();
          if (tenSecond > 5){
            minute++;
            tenSecond = 0;
            writeTenSecond();
            if (minute > 9){
              tenMinute++;
              minute = 0;
              writeMinute();
              writeTenMinute();
              if (tenMinute > 5){
                hour++;
                tenMinute = 0;
                writeTenMinute();
                if (hour > 9){
                  tenHour++;
                  hour = 0;
                  writeTenHour();
                }
              }
            }
            writeHour();
           }
          writeMinute();
        }
        writeSecond();
        second++;
        lapAllowed = 1;
        if (hour == 4 && tenHour == 2){
          resetTime();
        }
      }
      delay(1);  
      milli++;
    }
    
    void writeSecond(){
      lcd.setCursor(19, 0);
      lcd.print(second);
    }
    
    void writeTenSecond(){
      lcd.setCursor(18, 0);
      lcd.print(tenSecond);
    }
    
    void writeMinute(){
      lcd.setCursor(16, 0);
      lcd.print(minute);
    }
    
    void writeTenMinute(){
      lcd.setCursor(15, 0);
      lcd.print(tenMinute);
    }
    
    void writeHour(){
      lcd.setCursor(13, 0);
      lcd.print(hour);
    }
    
    void writeTenHour(){
      lcd.setCursor(12, 0);
      lcd.print(tenHour);
    }
    
    void resetTime(){
      milli = 1000;
      tenHour = 0;
      hour = 0;
      tenMinute = 0;
      minute = 0;
      tenSecond = 0;
      second = 0;
      lTenHour = 0;
      lHour = 0;
      lTenMinute = 0;
      lMinute = 0;
      lTenSecond = 0;
      lSecond = 0;
      lLTenHour = 0;
      lLHour = 0;
      lLTenMinute = 0;
      lLMinute = 0;
      lLTenSecond = 0;
      lLSecond = 0;
    
      lcd.setCursor(0, 0);
      lcd.print("Timer:      00:00:00");
      lcd.setCursor(0, 1);
      lcd.print("Lap:        00:00:00");
      lcd.setCursor(0, 2);
      lcd.print("Last:       00:00:00");
      lcd.setCursor(0, 3);
      lcd.print("       Reset        ");
    }
    
    void startLogic(){
      lcd.setCursor(0, 3);
      lcd.print("       Start        ");
    }
    
    void stopLogic(){
      lcd.setCursor(0, 3);
      lcd.print("        Stop        ");
      while (digitalRead(startButton) != LOW){
        if (digitalRead(lapButton) == LOW){
          lapLogic();
        }
        if (digitalRead(resetButton) == LOW){
          resetTime();
        }
        if (digitalRead(speedUpButton) == LOW){
          speedUp();
        }
        if (digitalRead(normalSpeedButton) == LOW){
          normalSpeed();
        }
      }
      startLogic();
    }
    
    void lapLogic(){
      if (lapAllowed == 1){
        lapAllowed = 0;
        lcd.setCursor(0, 3);
        lcd.print("        Lap         ");
        setLastLap();
        lTenHour = tenHour - lTenHour;
        lHour = hour - lHour;
        lTenMinute = tenMinute - lTenMinute;
        lMinute = minute - lMinute;
        lTenSecond = tenSecond - lTenSecond;
        lSecond = second - 1 - lSecond;
        lcd.setCursor(0, 1);
        lcd.print("Lap:        ");
        lcd.print(lTenHour);
        lcd.print(lHour);
        lcd.print(":");
        lcd.print(lTenMinute);
        lcd.print(lMinute);
        lcd.print(":");
        lcd.print(lTenSecond);
        lcd.print(lSecond);
      }
    }
    
    void setLastLap(){
      lcd.setCursor(0, 2);
      lcd.print("Last:       ");
      lcd.print(lTenHour);
      lcd.print(lHour);
      lcd.print(":");
      lcd.print(lTenMinute);
      lcd.print(lMinute);
      lcd.print(":");
      lcd.print(lTenSecond);
      lcd.print(lSecond);
    }
    
    void speedUp(){
      speedTime = 1;
    }
    
    void normalSpeed(){
      speedTime = 1000; 
    }

    0 Not allowed! Not allowed!

  2. #2
    I'ma Fuckin Scalie

    Feckless.'s Avatar
    Join Date
    Dec 2008
    Location
    F̷̧̨̙̞̱̥̓̄̂ͯ̃ͬ̚̚͟U&#
    Posts
    3,066
    Points
    8,699
         User Info     Contact     Gamer ID
    Join Date
    Dec 2008
    Location
    F̷̧̨̙̞̱̥̓̄̂ͯ̃ͬ̚̚͟U&#
    Posts
    3,066
    Points
    8,699
    Gamer IDs

    Gamertag: XEFDragon Steam ID: SketchyDragon

    Default

    That's pretty sick man. I love arduino, you can do some amazing stuff with it.

    0 Not allowed! Not allowed!
    P R O F E S S I O N A L S H I T P O S T E R



  3. #3
    Wii Code Creator
    T.U.F.F. PUPPY
    T.B.W's Avatar

    Badge

    Join Date
    Dec 2012
    Location
    Barcelona Spain
    Posts
    4,212
    Points
    6,669
         User Info     Contact     Gamer ID
    Join Date
    Dec 2012
    Location
    Barcelona Spain
    Posts
    4,212
    Points
    6,669

    Default

    Shit go hard as fuck man good job pretty sick....Creative

    0 Not allowed! Not allowed!

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -10. The time now is 08:23 PM.
Powered by vBulletin®
Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.