This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
MrBarry's profile picture

Clock that counts down to next phase change and drives slave clocks.

Started by MrBarry, 22 September 2012 - 09:13 PM
MrBarry #1
Posted 22 September 2012 - 11:13 PM
I made a clock which displays minutes and seconds left until nightfall during the day and the same until daybreak during the night. The exact time of daybreak and nightfall are configurable. By default, nightfall is the first time you can sleep. Daybreak was the first time my RP2 light sensor was activated.

Imgur album of my clock.

The clock uses a font file to display large numbers which you can customize to your liking. By default they are 7x4 in the style of a 7-segment LCD.

The master clock will run slave clocks over rednet. There are two slave programs. One to display on a monitor, the other to display in binary on any kind of redstone lamps over bundled cable. You'll just need to configure the bundled cable as pictured.

For the clock server, you need the files
clock
numbers –the font file
clockWriter –the functions to read the font and write to the monitor

For a client you'll need
clockSlave,
numbers,
and
clockWriter

or
clockSlaveBin

And remember to enunciate if you decide to say clockSlave out loud.

Wireless rednet is recommended. Rednet over cable works, but the slave is only updated every other second.

Feedback welcome.
Mr. Fang #2
Posted 24 September 2012 - 01:54 PM
Sounds like a great program! I'd love to run my Tekkit Factory that way!
TheBohush #3
Posted 27 September 2012 - 09:09 PM
Can you tell me how to run it please?
MrBarry #4
Posted 27 September 2012 - 11:29 PM
Can you tell me how to run it please?

Out of the box it should drive a 4x8 monitor connected to the back of the computer. Not sure if it will crash without a rednet modem connected, but if you want to be safe, connect a rednet modem to the top.
Download the files clock, numbers and clockWriter. Put those in the root (/) folder of your computer. Keep their names the same and in the same case.

Now, run "clock" and it should start writing the time to the monitor.

Parameters like the size of the text, the sides to which monitor and rednet are attached, and day/night transition times are set in the clock program file itself. If you want to run on a smaller monitor, I'd suggest changing mon.setTextScale(3.5) to mon.setTextScale(1) and going up or down depending on how it fits.

To display on a second monitor, download clockSlave, numbers and clockWriter to a second computer connected to its own monitor. Edit the clockSlave file to match your modem and monitor sides. Edit clock on the master computer and put the second computer's id in the table tClients{}. You can get rid of the numbers that are in there now. Save that, run clock on the master computer, then run clockSlave on the secondary computer. They should both display the same time now.

The binary slave clock is more complicated to set up. The program outputs the time over bundled cable as the set of colors associated with that particular number. The seconds displaying on the first 6 colors, and the minutes displaying on the next four colors. You can see the colors in order on the color api wiki page. I uploaded some better screenshots of my setup that might help. Of course, the side you connect the bundled cable to and the side of the rednet modem are configurable in the clockSlaveBin file. You only need the clockSlaveBin file for this particular clock, but of course its id has to be listed in the tClients table on the server clock. If you don't understand binary numbers, or the rs.setBundledOutput() function, you might want to skip this one.

If you get it working, post screenshots of your setup!
TheBohush #5
Posted 28 September 2012 - 08:23 AM
Can you tell me how to run it please?

Out of the box it should drive a 4x8 monitor connected to the back of the computer. Not sure if it will crash without a rednet modem connected, but if you want to be safe, connect a rednet modem to the top.
Download the files clock, numbers and clockWriter. Put those in the root (/) folder of your computer. Keep their names the same and in the same case.

Now, run "clock" and it should start writing the time to the monitor.

Parameters like the size of the text, the sides to which monitor and rednet are attached, and day/night transition times are set in the clock program file itself. If you want to run on a smaller monitor, I'd suggest changing mon.setTextScale(3.5) to mon.setTextScale(1) and going up or down depending on how it fits.

To display on a second monitor, download clockSlave, numbers and clockWriter to a second computer connected to its own monitor. Edit the clockSlave file to match your modem and monitor sides. Edit clock on the master computer and put the second computer's id in the table tClients{}. You can get rid of the numbers that are in there now. Save that, run clock on the master computer, then run clockSlave on the secondary computer. They should both display the same time now.

The binary slave clock is more complicated to set up. The program outputs the time over bundled cable as the set of colors associated with that particular number. The seconds displaying on the first 6 colors, and the minutes displaying on the next four colors. You can see the colors in order on the color api wiki page. I uploaded some better screenshots of my setup that might help. Of course, the side you connect the bundled cable to and the side of the rednet modem are configurable in the clockSlaveBin file. You only need the clockSlaveBin file for this particular clock, but of course its id has to be listed in the tClients table on the server clock. If you don't understand binary numbers, or the rs.setBundledOutput() function, you might want to skip this one.

If you get it working, post screenshots of your setup!

Thanks you for tut… but I got error… clockWriter:26: bad argument: string expected, got nil… can you help me with this?
MrBarry #6
Posted 28 September 2012 - 10:56 AM
Sounds like it is having trouble reading the numbers file. Do you have that downloaded, named numbers, and in the same folder as the other two files?
TheBohush #7
Posted 28 September 2012 - 12:11 PM
Sounds like it is having trouble reading the numbers file. Do you have that downloaded, named numbers, and in the same folder as the other two files?
Yes, I do
TheBohush #8
Posted 28 September 2012 - 12:27 PM
Sounds like it is having trouble reading the numbers file. Do you have that downloaded, named numbers, and in the same folder as the other two files?
Do I need to type: clock right.. or anything like that?
MrBarry #9
Posted 29 September 2012 - 01:07 AM
No, but you'll have to edit the top of the clock file to match your setup. ClockWriter line 26 is reading in the font file, though.

Pastebin seems to be cutting off the end of the numbers file. Edit it on the computer and add a couple newlines to the bottom. I will try to edit the program to make it tolerant of this, but as a quick fix for you, I think that will help.
MrBarry #10
Posted 29 September 2012 - 01:19 AM
OK, I've made some changes to clockWriter that should fix the font issue.
TheBohush #11
Posted 29 September 2012 - 07:03 AM
No, but you'll have to edit the top of the clock file to match your setup. ClockWriter line 26 is reading in the font file, though.

Pastebin seems to be cutting off the end of the numbers file. Edit it on the computer and add a couple newlines to the bottom. I will try to edit the program to make it tolerant of this, but as a quick fix for you, I think that will help.
Thanks you =) It works =D and can you add new program that will counts up? This is cool too =D But I want to use it for our tekkit server as big clock =D
MrBarry #12
Posted 30 September 2012 - 03:52 AM
Counts up? The main point of this program is to see how much daylight you have left, or how much time until sunrise. It's trivial to do the other.

Edit the clock program. Change

local tr = getRemaining()
to

local tr = textutils.formatTime(os.time(), true)
TheBohush #13
Posted 30 September 2012 - 11:14 AM
Counts up? The main point of this program is to see how much daylight you have left, or how much time until sunrise. It's trivial to do the other.

Edit the clock program. Change

local tr = getRemaining()
to

local tr = textutils.formatTime(os.time(), true)
I know =D but I need this to tekkit server as clock and I can't find any but I find this =D and Thanks You very much =D