30 posts
Location
The Darkness
Posted 12 February 2012 - 12:31 AM
Decided to make a project of making an in game digital clock
[youtube]
http://www.youtube.com/watch?v=38l8rH99mnk[/youtube]
12 hour display mode:
24 hour display mode
Wiring
Connection View
Spoiler
hourOut = "right"
minuteOut = "left"
twelveHour = true
function clear()
term.clear()
term.setCursorPos(1,1)
end
function formatTime(nTime)
local nHour = math.floor(nTime)
local nMinute = math.floor((nTime - nHour)*60)
if twelveHour == true and nHour >= 13 then
pmDot = true
nHour = nHour-12
else
pmDot = false
end
return string.format( "%02d:%02d", nHour, nMinute )
end
function readTime()
clear()
write "'q' to quit"
while true do
event, param = os.pullEvent()
if event == "redstone" then
encodeTime()
elseif event == "char" and param == "q" then
clear()
rs.setBundledOutput(hourOut, 0)
rs.setBundledOutput(minuteOut, 0)
break
end
end
end
function encodeTime()
gameTime = os.time()
eTime = formatTime(gameTime)
hour1 = string.sub(eTime, 1, 1)
eHour1 = tonumber(hour1)
hour2 = string.sub(eTime, 2, 2)
eHour2 = tonumber(hour2)
minute1 = string.sub(eTime, 4, 4)
eMinute1 = tonumber(minute1)
minute2 = string.sub(eTime, 5, 5)
eMinute2 = tonumber(minute2)
term.setCursorPos(8,6)
write (gameTime)
term.setCursorPos(8,7)
write (eTime)
cableSet()
end
function lowRegister()
if input == 0 then
lowValue = 63
elseif input == 1 then
lowValue = 3
elseif input == 2 then
lowValue = 109
elseif input == 3 then
lowValue = 103
elseif input == 4 then
lowValue = 83
elseif input == 5 then
lowValue = 118
elseif input == 6 then
lowValue = 126
elseif input == 7 then
lowValue = 35
elseif input == 8 then
lowValue = 127
elseif input == 9 then
lowValue = 115
else
end
end
function highRegister()
if input == 0 then
highValue = 8064
elseif input == 1 then
highValue = 384
elseif input == 2 then
highValue = 13952
elseif input == 3 then
highValue = 13184
elseif input == 4 then
highValue = 10624
elseif input == 5 then
highValue = 15104
elseif input == 6 then
highValue = 16128
elseif input == 7 then
highValue = 4480
elseif input == 8 then
highValue = 16256
elseif input == 9 then
highValue = 14720
else
end
end
function cableSet()
input = eHour1
highRegister()
input = eHour2
lowRegister()
rs.setBundledOutput(hourOut, highValue + lowValue + 32768)
input = eMinute1
highRegister()
input = eMinute2
lowRegister()
if pmDot == true then
rs.setBundledOutput(minuteOut, highValue + lowValue + 32768)
else
rs.setBundledOutput(minuteOut, highValue + lowValue)
end
end
readTime()
Silly code snippit tool makes my indentation all wonky.
Anyway, colon is fed power from the hour cable. the PM dot is fed power from the minute cable if 12 hour mode is true.
454 posts
Location
London
Posted 12 February 2012 - 12:50 AM
:(/>/> The else-if chain has returned from the ashes! :D/>/>
You should consider finding an alternative method for that, such as using sting.sub().
I'll give you some more code critique after that is fixed. ^_^/>/>
715 posts
Posted 12 February 2012 - 01:09 AM
Hey, nice clock.
I see you're feeding the 4 digits into 4 sides of the computer. You could bundle it up even more, though.
Since each side of the computer can take 16 bits off of a bundled cable you can combine the 14 segments of two digits into one side.
That means you'd only need three bundled cables going into your computer. 2 for the 4 digits and 1 for the colon.
But you could even add the colon signals to one of the digits-cable, because there's still room for 2 more bits.
Then you'd only have 2 bundled cables. ^_^/>/>
30 posts
Location
The Darkness
Posted 12 February 2012 - 01:12 AM
Yes but then i'd have to rewrite the driver script for the 7digit displays and… meh not interested in doing that at this time.
It works as intended so I'm going to work on other things for a while. I may come back to this and clean the code further later on.
As for the if..else structure, thats how it worked using my old structure, again something I didn't bother drastically changing for this version of the release. I mainly combined my existing code from the old method and changed the few points that needed to be altered.
715 posts
Posted 12 February 2012 - 01:24 AM
yes but then i'd have to rewrite the driver script for the 7digit displays and… meh not interested in doing that at this time.
Hehe, yeah the programming logic would need a rewrite, that's for sure.^^
And it all depends on need anyway, right? I mean, if you don't need that computer for anything else, then I guess it doesn't matter much.
I'm quite engaged in my own little project at the moment, or else I'd have done a 2-cabled clock myself, just for the heck of it.
Hmm… or can it be even more 'compressed'? Just for the heck of it?^^
Gnaaaah, now it got me again, damn side-experiments! It's all your fault Brigander! ^_^/>/>
3 posts
Posted 12 February 2012 - 02:00 AM
what wire did you used for the part thats being covered by the stone bridge
37 posts
Location
Quebec, Canada
Posted 12 February 2012 - 02:03 AM
Can I have your texture pack ^_^/>/>
715 posts
Posted 12 February 2012 - 02:13 AM
what wire did you used for the part thats being covered by the stone bridge
The specific color he used doesn't really matter, because he just has to remember which one it was when he wrote the code.
But to answer your question:
My guess is it is pink, because it looks like he just started from the beginning and went through the color-codes sequentially.
At least in too-many-items they appear in the order of the bits they represent, i.e. from 1 on upwards to 2^15.
And since pink is within the first 7 colors and he had to use 7 colors for his 7 segments of each digit
and pink is the only color that is missing in the picture, my guess is that it is exactly this color. Pink!^^
Edited on 12 February 2012 - 01:17 AM
3 posts
Posted 12 February 2012 - 02:28 AM
i just built it but it stays still….
i thought it would keep up with the time
30 posts
Location
The Darkness
Posted 12 February 2012 - 03:00 AM
Yes the last color is pink, tbh didn't think about it being covered up. and epicsky, it needs a timer pulse in order to update the time. note the timer attached to the redwire in the middle of the pic ^_^/>/>
30 posts
Location
The Darkness
Posted 12 February 2012 - 03:06 AM
Gr curses, now I can't get this blasted clock off my mind. (That and I finished the only other small project I had planned >_>) Gonna rewrite the code to use two cables >_>
496 posts
Location
Harlem, NY
Posted 12 February 2012 - 03:09 AM
Gr curses, now I can't get this blasted clock off my mind. (That and I finished the only other small project I had planned >_>) Gonna rewrite the code to use two cables >_>
Sounds good.
454 posts
Location
London
Posted 12 February 2012 - 03:31 AM
yes but then i'd have to rewrite the driver script for the 7digit displays and… meh not interested in doing that at this time.
Hehe, yeah the programming logic would need a rewrite, that's for sure.^^
And it all depends on need anyway, right? I mean, if you don't need that computer for anything else, then I guess it doesn't matter much.
I'm quite engaged in my own little project at the moment, or else I'd have done a 2-cabled clock myself, just for the heck of it.
Hmm… or can it be even more 'compressed'? Just for the heck of it?^^
Gnaaaah, now it got me again, damn side-experiments! It's all your fault Brigander! :P/>/>
I have the same problem: I was making a lock/unlock with some login for a computer. Then, I made the save/load snippet. And then, I made a matrix screensaver because I was bored ^_^/>/>
And Brig, you don't *really* have to worry about your code if it works, but it's always a good exercise.
30 posts
Location
The Darkness
Posted 12 February 2012 - 04:37 AM
Updated the code and pics in the first post.
Old Version Backup
Spoiler
Decided to make a project of making an in game digital clock
Spoiler
hour1out = "right"
hour2out = "back"
minute1out = "top"
minute2out = "left"
function clear()
term.clear()
term.setCursorPos(1,1)
end
function prime()
rs.setBundledOutput(hour1out, 127)
rs.setBundledOutput(hour1out, 63)
rs.setBundledOutput(hour2out, 127)
rs.setBundledOutput(hour2out, 63)
rs.setBundledOutput(minute1out, 127)
rs.setBundledOutput(minute1out, 63)
rs.setBundledOutput(minute2out, 127)
rs.setBundledOutput(minute2out, 63)
end
function formatTime(nTime)
local nHour = math.floor(nTime)
local nMinute = math.floor((nTime - nHour)*60)
--Uncomment this chunk to convert to 12 hour time, commenting makes it 24 hour.
--[[if nHour >= 13 then
nHour = nHour-12
end]]
return string.format( "%02d:%02d", nHour, nMinute )
end
function readTime()
clear()
write "'q' to quit"
while true do
event, param = os.pullEvent()
if event == "redstone" then
encodeTime()
elseif event == "char" and param == "q" then
clear()
rs.setBundledOutput(hour1out, 0)
rs.setBundledOutput(hour2out, 0)
rs.setBundledOutput(minute1out, 0)
rs.setBundledOutput(minute2out, 0)
break
end
end
end
function encodeHours()
if hours == "00" then
eHour1 = 0
eHour2 = 0
elseif hours == "01" then
eHour1 = 0
eHour2 = 1
elseif hours == "02" then
eHour1 = 0
eHour2 = 2
elseif hours == "03" then
eHour1 = 0
eHour2 = 3
elseif hours == "04" then
eHour1 = 0
eHour2 = 4
elseif hours == "05" then
eHour1 = 0
eHour2 = 5
elseif hours == "06" then
eHour1 = 0
eHour2 = 6
elseif hours == "07" then
eHour1 = 0
eHour2 = 7
elseif hours == "08" then
eHour1 = 0
eHour2 = 8
elseif hours == "09" then
eHour1 = 0
eHour2 = 9
elseif hours == "10" then
eHour2 = 1
eHour2 = 0
elseif hours == "11" then
eHour1 = 1
eHour2 = 1
elseif hours == "12" then
eHour1 = 1
eHour2 = 2
elseif hours == "13" then
eHour1 = 1
eHour2 = 3
elseif hours == "14" then
eHour1 = 1
eHour2 = 4
elseif hours == "15" then
eHour1 = 1
eHour2 = 5
elseif hours == "16" then
eHour1 = 1
eHour2 = 6
elseif hours == "17" then
eHour1 = 1
eHour2 = 7
elseif hours == "18" then
eHour1 = 1
eHour2 = 8
elseif hours == "19" then
eHour1 = 1
eHour2 = 9
elseif hours == "20" then
eHour1 = 2
eHour2 = 0
elseif hours == "21" then
eHour1 = 2
eHour2 = 1
elseif hours == "22" then
eHour1 = 2
eHour2 = 2
elseif hours == "23" then
eHour1 = 2
eHour2 = 3
else
end
end
function encodeMinutes()
if minutes == "00" then
eMinute1 = 0
eMinute2 = 0
elseif minutes == "01" then
eMinute1 = 0
eMinute2 = 1
elseif minutes == "02" then
eMinute1 = 0
eMinute2 = 2
elseif minutes == "03" then
eMinute1 = 0
eMinute2 = 3
elseif minutes == "04" then
eMinute1 = 0
eMinute2 = 4
elseif minutes == "05" then
eMinute1 = 0
eMinute2 = 5
elseif minutes == "06" then
eMinute1 = 0
eMinute2 = 6
elseif minutes == "07" then
eMinute1 = 0
eMinute2 = 7
elseif minutes == "08" then
eMinute1 = 0
eMinute2 = 8
elseif minutes == "09" then
eMinute1 = 0
eMinute2 = 9
elseif minutes == "10" then
eMinute1 = 1
eMinute2 = 0
elseif minutes == "11" then
eMinute1 = 1
eMinute2 = 1
elseif minutes == "12" then
eMinute1 = 1
eMinute2 = 2
elseif minutes == "13" then
eMinute1 = 1
eMinute2 = 3
elseif minutes == "14" then
eMinute1 = 1
eMinute2 = 4
elseif minutes == "15" then
eMinute1 = 1
eMinute2 = 5
elseif minutes == "16" then
eMinute1 = 1
eMinute2 = 6
elseif minutes == "17" then
eMinute1 = 1
eMinute2 = 7
elseif minutes == "18" then
eMinute1 = 1
eMinute2 = 8
elseif minutes == "19" then
eMinute1 = 1
eMinute2 = 9
elseif minutes == "20" then
eMinute1 = 2
eMinute2 = 0
elseif minutes == "21" then
eMinute1 = 2
eMinute2 = 1
elseif minutes == "22" then
eMinute1 = 2
eMinute2 = 2
elseif minutes == "23" then
eMinute1 = 2
eMinute2 = 3
elseif minutes == "24" then
eMinute1 = 2
eMinute2 = 4
elseif minutes == "25" then
eMinute1 = 2
eMinute2 = 5
elseif minutes == "26" then
eMinute1 = 2
eMinute2 = 6
elseif minutes == "27" then
eMinute1 = 2
eMinute2 = 7
elseif minutes == "28" then
eMinute1 = 2
eMinute2 = 8
elseif minutes == "29" then
eMinute1 = 2
eMinute2 = 9
elseif minutes == "30" then
eMinute1 = 3
eMinute2 = 0
elseif minutes == "31" then
eMinute1 = 3
eMinute2 = 1
elseif minutes == "32" then
eMinute1 = 3
eMinute2 = 2
elseif minutes == "33" then
eMinute1 = 3
eMinute2 = 3
elseif minutes == "34" then
eMinute1 = 3
eMinute2 = 4
elseif minutes == "35" then
eMinute1 = 3
eMinute2 = 5
elseif minutes == "36" then
eMinute1 = 3
eMinute2 = 6
elseif minutes == "37" then
eMinute1 = 3
eMinute2 = 7
elseif minutes == "38" then
eMinute1 = 3
eMinute2 = 8
elseif minutes == "39" then
eMinute1 = 3
eMinute2 = 9
elseif minutes == "40" then
eMinute1 = 4
eMinute2 = 0
elseif minutes == "41" then
eMinute1 = 4
eMinute2 = 1
elseif minutes == "42" then
eMinute1 = 4
eMinute2 = 2
elseif minutes == "43" then
eMinute1 = 4
eMinute2 = 3
elseif minutes == "44" then
eMinute1 = 4
eMinute2 = 4
elseif minutes == "45" then
eMinute1 = 4
eMinute2 = 5
elseif minutes == "46" then
eMinute1 = 4
eMinute2 = 6
elseif minutes == "47" then
eMinute1 = 4
eMinute2 = 7
elseif minutes == "48" then
eMinute1 = 4
eMinute2 = 8
elseif minutes == "49" then
eMinute1 = 4
eMinute2 = 9
elseif minutes == "50" then
eMinute1 = 5
eMinute2 = 0
elseif minutes == "51" then
eMinute1 = 5
eMinute2 = 1
elseif minutes == "52" then
eMinute1 = 5
eMinute2 = 2
elseif minutes == "53" then
eMinute1 = 5
eMinute2 = 3
elseif minutes == "54" then
eMinute1 = 5
eMinute2 = 4
elseif minutes == "55" then
eMinute1 = 5
eMinute2 = 5
elseif minutes == "56" then
eMinute1 = 5
eMinute2 = 6
elseif minutes == "57" then
eMinute1 = 5
eMinute2 = 7
elseif minutes == "58" then
eMinute1 = 5
eMinute2 = 8
elseif minutes == "59" then
eMinute1 = 5
eMinute2 = 9
else
end
end
function encodeTime()
gameTime = os.time()
eTime = formatTime(gameTime)
hours = string.sub(eTime, 1, 2)
minutes = string.sub(eTime, 4, 5)
encodeHours()
encodeMinutes()
term.setCursorPos(8,6)
write (gameTime)
term.setCursorPos(8,7)
write (eTime)
term.setCursorPos(8,8)
write (hours)
term.setCursorPos(11,8)
write (minutes)
pushTime()
end
function interpret()
if input == 0 then
rs.setBundledOutput(cableout, 63)
elseif input == 1 then
rs.setBundledOutput(cableout, 3)
elseif input == 2 then
rs.setBundledOutput(cableout, 109)
elseif input == 3 then
rs.setBundledOutput(cableout, 103)
elseif input == 4 then
rs.setBundledOutput(cableout, 83)
elseif input == 5 then
rs.setBundledOutput(cableout, 118)
elseif input == 6 then
rs.setBundledOutput(cableout, 126)
elseif input == 7 then
rs.setBundledOutput(cableout, 35)
elseif input == 8 then
rs.setBundledOutput(cableout, 127)
elseif input == 9 then
rs.setBundledOutput(cableout, 115)
elseif input == 10 then
rs.setBundledOutput(cableout, 0)
else
end
end
function pushTime()
input = eHour1
cableout = hour1out
interpret()
input = eHour2
cableout = hour2out
interpret()
input = eMinute1
cableout = minute1out
interpret()
input = eMinute2
cableout = minute2out
interpret()
end
prime()
readTime()
Silly code snippit tool makes my indentation all wonky.
4 posts
Posted 12 February 2012 - 11:59 AM
I can't get this to work…, I got a cable on the left and on the right of the computer and is running it program, but none of the wires are powered
I don't know if having the program on a disc like you seem to have, will make a difference? I am new to all the computer stuff, in Minecraft that is.
EDIT:nevermind, you must have a hidden timer somewhere? manage to find out you need one from reading your code
Edited on 12 February 2012 - 12:11 PM
715 posts
Posted 12 February 2012 - 12:54 PM
Updated the code and pics in the first post.
Hehe, it didn't let you go, heh?^^
Looks nice now and very streamlined.
You still left the colon on a separate cable though. *trollface*Nah, just kidding, that was just my ocd talking. Pay no attention to it. ^_^/>/>
30 posts
Location
The Darkness
Posted 12 February 2012 - 05:56 PM
You still left the colon on a separate cable though. *trollface*
Nah, just kidding, that was just my ocd talking. Pay no attention to it. ^_^/>/>
Anyway, colon is fed power from the hour cable. the PM dot is fed power from the minute cable if 12 hour mode is true.
No I didn't =P purely off of the two cables. I'll get a shot of the connections to add to the description.
715 posts
Posted 12 February 2012 - 06:24 PM
You still left the colon on a separate cable though. *trollface*
Nah, just kidding, that was just my ocd talking. Pay no attention to it. :P/>/>
Anyway, colon is fed power from the hour cable. the PM dot is fed power from the minute cable if 12 hour mode is true.
No I didn't =P purely off of the two cables. I'll get a shot of the connections to add to the description.
Oh ok, just saw the new image. Yeah, it seems I misinterpreted the other image then.^^
You even wrote about it, but I totally missed that. My bad, sorry!
brigander.flushMemory() *this never happened…* ^_^/>/>
30 posts
Location
The Darkness
Posted 16 February 2012 - 12:07 AM
Added an actual video in the OP. Enjoy.
496 posts
Location
Harlem, NY
Posted 16 February 2012 - 05:18 AM
Added an actual video in the OP. Enjoy.
Awesome video, nice IR is jumping on this mod, hard not to with stuff like this :D/>/>
30 posts
Location
The Darkness
Posted 16 February 2012 - 06:41 AM
Its installed, just trying to get the kinks ironed out from the transition to 1.1 >_>
26 posts
Posted 22 February 2012 - 01:22 AM
I like the clock and all but when using it i can't seem to get the clock to keep the minute updated to each minute but it only updates every 10 could it be and indentation problem or pure user error…. and yes i have the same set up made here :huh:/>/>
30 posts
Location
The Darkness
Posted 22 February 2012 - 01:28 AM
What rate is your timer set to?
Try setting it to .8 seconds in order to get the minute digits to move properly.
26 posts
Posted 22 February 2012 - 02:36 AM
tired that any other suggestions and also im going to look in the code to see if its all good on my part
*Edit*
I found out that the last digit of the minute is off timing…
Looked at the code and can't figure out what is up.
58 posts
Posted 22 February 2012 - 08:19 AM
Very nice setup, Brig. also, to those who ask while I'm streaming the clock on my map is a replica of this clock XD nothing more nothing less.
On a side note: I tried to build this in littleblocks… I was nearly finished when I realized I couldnt adjust the timer with littleblocks… I'll look into a CC based timer to see if I can resolve some issues I have and if I get it finished I'll stream it and save that clip ^^ (in littleblocks it would only take up like four or so blocks, so it'd make a nice wall clock
42 posts
Location
Germany
Posted 22 February 2012 - 04:23 PM
can someone move this to the peripheral section please?
411 posts
Posted 22 February 2012 - 04:30 PM
its not a peripheral?
58 posts
Posted 22 February 2012 - 09:09 PM
would be interesting and certainly smaller if it were a peripheral but I think that would also take the challenge out of building it :x
26 posts
Posted 23 February 2012 - 02:20 PM
Hey still having problems with the clock not changing every minute and its the last digit of the clock on the minute side that is stuck.
How is the function cableSet() segment suppose to be indented i think that is where my problem may be occuring.
58 posts
Posted 23 February 2012 - 02:36 PM
Hey still having problems with the clock not changing every minute and its the last digit of the clock on the minute side that is stuck.
How is the function cableSet() segment suppose to be indented i think that is where my problem may be occuring.
clock not updating: you do have a timer on it, right? *points to the top down view image*derpderpderp, I havent entirely woken up yet
Edited on 23 February 2012 - 01:41 PM
30 posts
Location
The Darkness
Posted 23 February 2012 - 05:54 PM
Hey still having problems with the clock not changing every minute and its the last digit of the clock on the minute side that is stuck.
How is the function cableSet() segment suppose to be indented i think that is where my problem may be occuring.
Er indentation is for readability it has no impact on how the program functions…
26 posts
Posted 23 February 2012 - 11:25 PM
Hmmm…idk maybe just me ill try again later but my setup is right… its exactly like the picture….
I reput the code in and doesnt work still but i have to ask do you put it in its own .lua file or write it into the computer manually thorugh mc…. I dont know what i have done wrong but i really want this to work
*Edit*
Since I want to learn to code this stuff anyway ill make my first self project a clock for myself….If this is ok…. I think it'll be a good thing to get me started jsut need to know how to get it going but I'll figure it out some how…
Thanks for the help… and also thanks Brigander for the cool clock…
4 posts
Posted 24 February 2012 - 05:26 AM
Did something changed in ComputerCraft?? because this just stopped powering the cables after I update to 1.3. The clock in the terminal(when I right click on it) is still working, but it is not outputting to the cables.
3 posts
Location
California
Posted 27 February 2012 - 05:29 AM
Very nice setup, Brig. also, to those who ask while I'm streaming the clock on my map is a replica of this clock XD nothing more nothing less.
On a side note: I tried to build this in littleblocks… I was nearly finished when I realized I couldnt adjust the timer with littleblocks… I'll look into a CC based timer to see if I can resolve some issues I have and if I get it finished I'll stream it and save that clip ^^ (in littleblocks it would only take up like four or so blocks, so it'd make a nice wall clock
i tried to make this in littleblocks, but the lamps dont show up, and the wires dont show up either…
what versions did you use?
514 posts
Location
Over there
Posted 06 March 2012 - 04:31 PM
Can I use the time encoding and formating functions for my alarm clock?
Of course I'll credit you!