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

20 Character Alphanumeric Display [ComputerCraft & RedPower 2]

Started by peterthefoxx, 30 March 2012 - 03:36 PM
peterthefoxx #1
Posted 30 March 2012 - 05:36 PM
Basically,


=== Videos ===
SpoilerDemo Video
[media]http://www.youtube.com/watch?v=iQWZJBIm8qU[/media]

Display setup and usage!
[media]http://youtu.be/-NLOhJQhnh4[/media]

=== Build Log ===
Spoiler1 - The Font
My first task was to create the font so I could determine how big the screen would need to be.

Inspiration: 16 Segment LED Displays

However 16 Segments looked to blocky for lower-case characters and symbols. The image below shows the discarded 16 segment design, and the improved 48 segment layout created just for this project.



I also discarded a 32 segment design too -.-


2 - Converting the font into lua
Each letter is a series of segment numbers as seen above, however I cba to write out all the segment numbers into arrays, so I simply made a macro in VBA to copy out the numbers of the green cells and put them into a big lua 'if' 'else' statement for each letter, this would then return an array like so:


function getSegmentsForCharacter(character)

if character == " " then
		return {}
	elseif character == "i" then
		return {3,14,21,27,33,39}
	elseif character == "j" then
		return {3,14,21,27,33,39,42,44,47}
.. etc


3 - Making the first 48 segment display

[This is where the RedPower 2 Mod comes in!]

After finding a suitable place to put the display, I simply placed lamps into the shape as designed in Excel, and connected the relevant coloured wire to the relevant lamp using the colour numbers below with the leftmost design in excel:



Then… 3 bundled cables for the 3x16 segments and a computer:



The OR gate connects the brown (13) and green (14) wires with the white wire circled above, because that pixel is shared between segments 13 and 14 and should come on if either are activated.

Note: see the red and black bundled cables below the computer - this connects to the previous and next segment computer (see below).


4 - Almost Done…
Creating the program - Here is the code, look at the code under '– main' to get an idea of how it all works.

Note: displayCharacter("A") would display the letter A on the connected segment display etc.

Note: Step 6 gives an explaination on the code below regarding how the character is determined.

The Code:
Spoiler


-- ensure APIs are loaded
os.loadAPI("font_fox48")	-- lets us use this: font_fox48.getSegmentsForCharacter(character)


-- variables
colorNumbers = {colors.white, colors.orange, colors.magenta, colors.lightBlue, colors.yellow, colors.lime, colors.pink, colors.gray, colors.lightGray, colors.cyan, colors.purple, colors.blue, colors.brown, colors.green, colors.red, colors.black}


-- functions
function clearDisplay()
	redstone.setBundledOutput("right", 0)
	redstone.setBundledOutput("top", 0)
	redstone.setBundledOutput("back", 0)
end

function displayCharacter(character)

	characterSegments = font_fox48.getSegmentsForCharacter(character)
	
	i = table.getn(characterSegments)
	
	if (i > 0) then
	
		outputTop = 0	-- 1 to 16
		outputMiddle = 0	-- 17 to 32
		outputBottom = 0	-- 33 to 48
		
		while i > 0 do
			
			segment = characterSegments[i]
			
			if (segment <= 16) then
				
				outputTop = colors.combine(outputTop, colorNumbers[segment])
				
			elseif (segment <= 32) then
				segment = segment - 16
				
				outputMiddle = colors.combine(outputMiddle, colorNumbers[segment])
				
			elseif (segment <= 48) then
				segment = segment - 32
				
				outputBottom = colors.combine(outputBottom, colorNumbers[segment])
			end
			
			i = i - 1
		end
		
		redstone.setBundledOutput("right", outputTop)
		redstone.setBundledOutput("top", outputMiddle)
		redstone.setBundledOutput("back", outputBottom)
		
	else
		clearDisplay()
	end
	
end


-- main

lastInput = 0

while true do
	
	input = redstone.getBundledInput("bottom")
	
	if lastInput ~= input then
		lastInput = input
		
		if input == 0 then
			clearDisplay()
			redstone.setBundledOutput("left", 0)
		elseif input <= 128 then
			displayCharacter(string.char(input))
		else
			redstone.setBundledOutput("left", input - 128)
		end
	end
	
	sleep(0.2)
end


5 - One more thing (or maybe 19)
Then I repeated step 2, 19 more times -.-, and copied the program to every segment pc.

Note: This design is scalable - the segments are daisy chained and the signal cable supports 65535 combinations (2 [on or off] to the power of 16 lines = 2^16), which is 500x 128 (the ascii charset) so that means: You could have any number of characters from 1 to little over 500 all running from a single bundled cable - that is, if minecraft could handle it :] …oh and not to mention you could have 6 of those cables coming from 1 computer, making a total of 3000 characters (…oh and having more of those computers.. etc), but alas - if minecraft and my actual pc would be infinitely more powerful.

Side Note: Don't try to make them all change character every second, else this


6 - The Actual Final Step, a controller PC
The controller pc will need to send a letter to each segment pc, but it is only connected to the first segment!?!

Well basically:
to send a character to the 1st segment you would send the number: 128 * 0 + character code
to send a character to the 2nd segment you would send the number: 128 * 1 + character code
to send a character to the 3rd segment you would send the number: 128 * 2 + character code

Because if the number is larger than 128, when it reaches a segment, the segment will minus 128 and pass it on to the next screen. Until eventually the number is 128 or less, then that segment will display it and will not pass anything to the next letter.

So all we need is some code like this:



input = ""

while input ~= "quitme" do
	
	print ("Text to display: ")
	print ("|------------------|")	-- 20 characters guide (messages longer than this line will be cut off at the end)
	input = io.read()
	
	if input ~= nil then	-- probably a pointless check for nil, ah well
		
		i = 0
		
		while i < string.len(input) do
		
			char = string.byte(input, i + 1)
			print(i)
			char = char + (i * 128)
			
			redstone.setBundledOutput("back", char)
			
			sleep(0.3)	-- ensure this is the same (or slightly longer for safety) than the segment tick rate.
			i = i + 1
		end
	end
end

Fin.

=== Downloads ===
This creation requires, Minecraft 1.2.3, ComputerCraft, All RedPower 2 modules [Prerelease 4e]

– World (includes lua) –
Just unzip into your Minecraft 'saves' folder
World 8.2 MB
Please see the videos section for a guide to setting up and using the display!

– lua –
seg48ctl
seg48
fox_font48

btw, a big thanks to Dan200 and Eloraam for these awesome mods!
Wolvan #2
Posted 30 March 2012 - 06:00 PM
I want it. I NEED IT!
peterthefoxx #3
Posted 31 March 2012 - 03:34 AM
Thanks for the interest Wolvan, I have now updated and uploaded the world save file (and a video to go with it). Enjoy!

I aim to make this into at least a 2 line display, or at least work on making it update faster, also perhaps cleaning up the code and packaging it nicely into an API… so many options, so little time :o/>/>

BTW, feel free to include anything from this in your own projects, if anyone releases their own adaptation of something from this project I am always interested in seeing what you come up with :]
Ludburghmdm #4
Posted 31 March 2012 - 03:42 AM
Whoa! I just updated my post and found out that you also posted the world download here!

I was really looking forward to playing with this…but sadly, i updated my Minecraft Client to 1.2.4 and RP2 isn't updated to 1.2.4 yet :o/>/>
peterthefoxx #5
Posted 31 March 2012 - 12:03 PM
yeah, I am also anticipating redpower's support for 1.2.4 - once this is done I will upload a new version
peterthefoxx #6
Posted 03 April 2012 - 11:37 PM
A sneak preview of v2:

Features:
- Added 3 more lines (wow if only I had used mcedit for the fist line ¬.¬)
- v1 API created, allows programs to display text simply by providing the text, x position and line number to the API.
- API functions have some optimisations over previous controller code.
- time48 demo program created to demo new features (see screenshot)
- The display now starts up automatically so you don't need to start every computer each time you start the game!

Speed optimisations that allow 20 x 48 x 4 (3840) segments to work without exploding my pc:
- Computers store their position in a file rather than being daisy-chained allowing the computer to be connected directly to the signal wire for ultra speed
- More Computers added to split up the signal wire (one per line) so the signal only routes to necessary line
- Ultra speed slightly negated by having 4 lines (but it's still slightly faster than the single line before)

Note: An idea of the speed of this display: the demo program in the screenshot below updates every minecraft minute (every 1 second real time!) - although that's achieved by using the API functions so that only a few characters need to be updated at once!

Video + Downloads coming soon!