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

Simple sample program for graphing redstone input

Started by ajthemacboy, 25 September 2015 - 06:57 PM
ajthemacboy #1
Posted 25 September 2015 - 08:57 PM
Hello, I'm pretty new to ComputerCraft, but I'm familiar with C++ and Lua doesn't seem that different, so I'm trying to learn.

I'm looking for a program that graphs the input from a redstone signal into a computer over around a minute, and displays it on a monitor.

I would like a sample program, not individual instructions, if anyone can write one up real quick.

Thanks!
Lyqyd #2
Posted 26 September 2015 - 12:51 AM
Moved to General.
Waitdev_ #3
Posted 26 September 2015 - 02:34 AM
a little offtopic, but if you want to learn lua i recommend direwolf20's computercraft tutorials.
H4X0RZ #4
Posted 27 September 2015 - 01:14 AM
a little offtopic, but if you want to learn lua i recommend direwolf20's computercraft tutorials.

I guess it would be better to learn the actual language first instead of jumping right into the APIs. Atleast the syntax because the OP knows another language already. If the OP has a basic understanding of lua he could/should begin with CC. Else you'll get more confused than "needed".
KingofGamesYami #5
Posted 27 September 2015 - 01:47 AM
Well, this seems like a fun little piece of code to write…

local data = {}
for k, v in pairs( rs.getSides() ) do
  data[ v ] = {}
end

for i = 1, 60 do
  for side, tbl in pairs( data ) do
    tbl[ i ] = rs.getAnalogInput( side )
  end
  sleep( 1 )
end

--#wohoo, we've got the data!  Now to graph it...

local cSides = {
  right = colors.green,
  left = colors.yellow,
  top = colors.blue,
  bottom = colors.red,
  front = colors.purple,
  back = colors.white,
}

local mon = peripheral.find( "monitor", function( name, handle ) return handle.isColor() end )
if not mon then
  error( "No advanced monitors found!", 0 )
end

mon.setBackgroundColor( colors.black )
mon.clear()
for side, tbl in pairs( data ) do
  mon.setBackgroundColor( cSides[ side ] )
  for i = 1, 60 do
    mon.setCursorPos( i, data[ i ] )
    mon.write( " " )
  end
end
Edited on 26 September 2015 - 11:47 PM