How to Program a Clock

by -_ - wAT in Circuits > Computers

19007 Views, 30 Favorites, 0 Comments

How to Program a Clock

clock13.JPG

If you have ever wanted to create and control time, this is not exactly the right place. I can, however, teach you how to write a program for a clock. I will be showing you how to use Notepad on a Windows computer to design your very own program in the batch language.

To be honest with everyone reading this, if you don't really want to read all that I type, the pictures are self-explanatory for the most part.

WARNING: IT IS ILLEGAL TO DISTRIBUTE BATCH FILES OVER THE INTERNET.



Materials: Windows Computer, Notepad

Open Notepad

Clock2.JPG

Open Notepad... If you don't know how to open Notepad then you shouldn't program a clock.

Starting It

Clock3.JPG

To start off, type

@echo off

this code is basically saying that you want your program to display something.

Still Starting It

clock4.JPG

The next code on a new line is

:start

The " : " means that you have a specific point you want to return to. I then typed "start" to specify a name for this point. You can use whatever you want, i only used "start" for the sake of simplicity.

Getting Into It

clock7.JPG

More code

cls

This code is just a shortened version of the words "Clear Screen". And that is what it does. Later on we will find that clearing the screen makes the program run smoother and visually attractive.

Timing

clock8.JPG

Codes, codes, codes

echo %time%

The code "echo" tells the program to prompt whatever follows on that line.

The %time% just means to display the time that the computer has.

Goto Step 6

clock9.JPG

[Insert funny one-liner here]

goto start

Whoever made this programming language honestly just put the words "go" and "to" together and made it go to a specified point. In this case, I made it go back to "start". Don't Pass Go. Don't Collect 200.

Don't Forget to Save

clock0.JPG

Saving a program from Notepad is different from saving a text document. There are a few step you must take for it to work correctly.

  1. Where it says "Save as type", choose the option "All Files".
  2. Save your program as Clock.bat . The ".bat" tells the computer what programming language you used

Choose a safe place to save this and hit save.

You Are a Programmer Now

You have now officially written a program. Now if you open it you may notice that it looks a little sketchy, but no worries. These next few steps will show you how to amp up your program.

Make It Pretty

clock10.JPG

Lets add some color to our project. Add the command

color 0a

to a new line under "@echo off". "0a" Is just a color code for light green text on a black background. You can use any color combination you want, but 0a is the most stereotypical color scheme for a hacker.

Make It Prettier

clcok11.JPG

If you opened the program then you would have noticed that it flashed each time at you. I found this to be distracting and ugly, so I added the command:

timeout 0 /nobreak>null

This is a more advanced command, so I won't explain it all to you. It basically tell the program to wait for "0" seconds and then continue without letting the user know it paused. If you look up the "timeout command", you can learn more.

It's So Pretty

clcok 12.JPG

Almost done. Add the command:

title Clock

on the first line, on its own line.(Reference the picture above). This just make the name of window that will open "Clock".

And now you're Done.

It's All Over Now

clock54.JPG

When you open it now it should look a lot nicer and more appealing. I simply shrunk mine down to a reasonable size.

This was the first program I ever wrote when I was first starting out (Not as advanced obviously) and still enjoy the look of it. I hope to have inspired all of you to carry on with writing programs, but if not, at least you have a new clock.

Have a good day while never having to worry about what time it is ever again.

WARNING: DO NOT DISTRIBUTE ANY BATCH FILES OVER THE INTERNET, THEY CAN CAUSE HARM TO OTHERS' MACHINES EASILY. NEVER DOWNLOAD A BATCH FILE FROM THE INTERNET. NEVER OPEN A BATCH FILE BEFORE YOU ARE 105.7% SURE IT IS SAFE. I AM NOT RESPONSIBLE FOR ANY HARM CAUSED TO YOUR MACHINE.