<- Back

Clock

Dec. 24, 2015 - cheapie

For this project, the mesecons, digilines, and rgblightstone mods are required. The digibutton mod is recommended, but it is possible to complete this without it.


The story behind this one is quite similar to the Tic-Tac-Toe machine. Uberi's version is nice and all, but uses 22 Luacontrollers. It's easy enough to reduce this to 21, but any fewer than that requires a smarter display. With RGB Lightstone, one LuaC does the job.


Step 1: Display

Start with a 17 wide by 5 tall panel of digimese or digilines. On the front of this, place a block of RGB Lightstone in the top left corner, and set it for channel "d", X address 1, and Y address 1. Continue this line to the right, incrementing the X address each time. The far right should have an X address of 17. Next, place another row below these and punch each one. Repeat until the entire front of the digimese is covered. If done correctly, the bottom-right RGB Lightstone will have an X address of 17 and a Y address of 5.


Step 2: Controller

On top of the display's digilines or digimese, place another digiline or digimese block (anywhere works except the end). On one side, place a digilines RTC, and on the other, a Luacontroller with blinky plant.

Now, set the RTC to the channel "clock", and program the Luacontroller with the following code:

--RGB Lightstone Clock
--Written by cheapie, WTFPL

function format_time(time)
	local hour=math.floor(time*24)%10
	local minute=math.floor(((time*24)%1)*60)%10
	local tenhour=math.floor(math.floor(time*24)/10)
	local tenminute=math.floor(math.floor(((time*24)%1)*60)/10)
	return tenhour,hour,tenminute,minute
end

if event.type=="program" then
mem.fgcolor = "darkblue"
mem.bgcolor = "black"
mem.th = 0
mem.h = 0
mem.tm = 0
mem.m = 0
mem.colon = false
mem.font={}
mem.font["blank"]={
{mem.bgcolor,mem.bgcolor,mem.bgcolor},
{mem.bgcolor,mem.bgcolor,mem.bgcolor},
{mem.bgcolor,mem.bgcolor,mem.bgcolor},
{mem.bgcolor,mem.bgcolor,mem.bgcolor},
{mem.bgcolor,mem.bgcolor,mem.bgcolor}
}
mem.font[0]={
{mem.fgcolor,mem.fgcolor,mem.fgcolor},
{mem.fgcolor,mem.bgcolor,mem.fgcolor},
{mem.fgcolor,mem.bgcolor,mem.fgcolor},
{mem.fgcolor,mem.bgcolor,mem.fgcolor},
{mem.fgcolor,mem.fgcolor,mem.fgcolor}
}
mem.font[1]={
{mem.bgcolor,mem.fgcolor,mem.bgcolor},
{mem.fgcolor,mem.fgcolor,mem.bgcolor},
{mem.bgcolor,mem.fgcolor,mem.bgcolor},
{mem.bgcolor,mem.fgcolor,mem.bgcolor},
{mem.fgcolor,mem.fgcolor,mem.fgcolor}
}
mem.font[2]={
{mem.fgcolor,mem.fgcolor,mem.fgcolor},
{mem.bgcolor,mem.bgcolor,mem.fgcolor},
{mem.bgcolor,mem.fgcolor,mem.bgcolor},
{mem.fgcolor,mem.bgcolor,mem.bgcolor},
{mem.fgcolor,mem.fgcolor,mem.fgcolor}
}
mem.font[3]={
{mem.fgcolor,mem.fgcolor,mem.fgcolor},
{mem.bgcolor,mem.bgcolor,mem.fgcolor},
{mem.fgcolor,mem.fgcolor,mem.fgcolor},
{mem.bgcolor,mem.bgcolor,mem.fgcolor},
{mem.fgcolor,mem.fgcolor,mem.fgcolor}
}
mem.font[4]={
{mem.fgcolor,mem.bgcolor,mem.fgcolor},
{mem.fgcolor,mem.bgcolor,mem.fgcolor},
{mem.fgcolor,mem.fgcolor,mem.fgcolor},
{mem.bgcolor,mem.bgcolor,mem.fgcolor},
{mem.bgcolor,mem.bgcolor,mem.fgcolor}
}
mem.font[5]={
{mem.fgcolor,mem.fgcolor,mem.fgcolor},
{mem.fgcolor,mem.bgcolor,mem.bgcolor},
{mem.fgcolor,mem.fgcolor,mem.bgcolor},
{mem.bgcolor,mem.bgcolor,mem.fgcolor},
{mem.fgcolor,mem.fgcolor,mem.bgcolor}
}
mem.font[6]={
{mem.fgcolor,mem.fgcolor,mem.fgcolor},
{mem.fgcolor,mem.bgcolor,mem.bgcolor},
{mem.fgcolor,mem.fgcolor,mem.fgcolor},
{mem.fgcolor,mem.bgcolor,mem.fgcolor},
{mem.fgcolor,mem.fgcolor,mem.fgcolor}
}
mem.font[7]={
{mem.fgcolor,mem.fgcolor,mem.fgcolor},
{mem.bgcolor,mem.bgcolor,mem.fgcolor},
{mem.bgcolor,mem.bgcolor,mem.fgcolor},
{mem.bgcolor,mem.fgcolor,mem.bgcolor},
{mem.fgcolor,mem.bgcolor,mem.bgcolor}
}
mem.font[8]={
{mem.fgcolor,mem.fgcolor,mem.fgcolor},
{mem.fgcolor,mem.bgcolor,mem.fgcolor},
{mem.fgcolor,mem.fgcolor,mem.fgcolor},
{mem.fgcolor,mem.bgcolor,mem.fgcolor},
{mem.fgcolor,mem.fgcolor,mem.fgcolor}
}
mem.font[9]={
{mem.fgcolor,mem.fgcolor,mem.fgcolor},
{mem.fgcolor,mem.bgcolor,mem.fgcolor},
{mem.fgcolor,mem.fgcolor,mem.fgcolor},
{mem.bgcolor,mem.bgcolor,mem.fgcolor},
{mem.fgcolor,mem.fgcolor,mem.fgcolor}
}
end

function render(th,h,tm,m,colon)
	buffer={{mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor},
{mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor},
{mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor},
{mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor},
{mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor},
{mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor},
{mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor,mem.bgcolor}}
	thchar = mem.font[th]
	hchar = mem.font[h]
	tmchar = mem.font[tm]
	mchar = mem.font[m]
	buffer[1][1] = thchar[1][1]
	buffer[1][2] = thchar[1][2]
	buffer[1][3] = thchar[1][3]
	buffer[2][1] = thchar[2][1]
	buffer[2][2] = thchar[2][2]
	buffer[2][3] = thchar[2][3]
	buffer[3][1] = thchar[3][1]
	buffer[3][2] = thchar[3][2]
	buffer[3][3] = thchar[3][3]
	buffer[4][1] = thchar[4][1]
	buffer[4][2] = thchar[4][2]
	buffer[4][3] = thchar[4][3]
	buffer[5][1] = thchar[5][1]
	buffer[5][2] = thchar[5][2]
	buffer[5][3] = thchar[5][3]
	buffer[1][5] = hchar[1][1]
	buffer[1][6] = hchar[1][2]
	buffer[1][7] = hchar[1][3]
	buffer[2][5] = hchar[2][1]
	buffer[2][6] = hchar[2][2]
	buffer[2][7] = hchar[2][3]
	buffer[3][5] = hchar[3][1]
	buffer[3][6] = hchar[3][2]
	buffer[3][7] = hchar[3][3]
	buffer[4][5] = hchar[4][1]
	buffer[4][6] = hchar[4][2]
	buffer[4][7] = hchar[4][3]
	buffer[5][5] = hchar[5][1]
	buffer[5][6] = hchar[5][2]
	buffer[5][7] = hchar[5][3]
	buffer[2][9] = colon and mem.fgcolor or mem.bgcolor
	buffer[4][9] = colon and mem.fgcolor or mem.bgcolor
	buffer[1][11] = tmchar[1][1]
	buffer[1][12] = tmchar[1][2]
	buffer[1][13] = tmchar[1][3]
	buffer[2][11] = tmchar[2][1]
	buffer[2][12] = tmchar[2][2]
	buffer[2][13] = tmchar[2][3]
	buffer[3][11] = tmchar[3][1]
	buffer[3][12] = tmchar[3][2]
	buffer[3][13] = tmchar[3][3]
	buffer[4][11] = tmchar[4][1]
	buffer[4][12] = tmchar[4][2]
	buffer[4][13] = tmchar[4][3]
	buffer[5][11] = tmchar[5][1]
	buffer[5][12] = tmchar[5][2]
	buffer[5][13] = tmchar[5][3]
	buffer[1][15] = mchar[1][1]
	buffer[1][16] = mchar[1][2]
	buffer[1][17] = mchar[1][3]
	buffer[2][15] = mchar[2][1]
	buffer[2][16] = mchar[2][2]
	buffer[2][17] = mchar[2][3]
	buffer[3][15] = mchar[3][1]
	buffer[3][16] = mchar[3][2]
	buffer[3][17] = mchar[3][3]
	buffer[4][15] = mchar[4][1]
	buffer[4][16] = mchar[4][2]
	buffer[4][17] = mchar[4][3]
	buffer[5][15] = mchar[5][1]
	buffer[5][16] = mchar[5][2]
	buffer[5][17] = mchar[5][3]
	return(buffer)
end


if event.type == "on" then
	digiline_send("clock","GET")
elseif event.type == "digiline" and event.channel == "clock" and event.msg ~= "GET" then
	local th,h,tm,m = format_time(event.msg)
	mem.colon = not mem.colon
	digiline_send("d",render(th,h,tm,m,mem.colon))
end

And.... that's it! The clock should come on and immediately start displaying the current (Minetest) time. No setting needed.