Jump to content




Simple sample program for graphing redstone input

computer

  • You cannot reply to this topic
4 replies to this topic

#1 ajthemacboy

  • Members
  • 3 posts

Posted 25 September 2015 - 07: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!

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

Posted 25 September 2015 - 11:51 PM

Moved to General.

#3 Waitdev_

  • Members
  • 432 posts
  • LocationAdelaide

Posted 26 September 2015 - 01:34 AM

a little offtopic, but if you want to learn lua i recommend direwolf20's computercraft tutorials.

#4 H4X0RZ

  • Members
  • 1,315 posts
  • LocationGermany

Posted 27 September 2015 - 12:14 AM

View PostWait_, on 26 September 2015 - 01:34 AM, said:

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".

#5 KingofGamesYami

  • Members
  • 3,002 posts
  • LocationUnited States of America

Posted 27 September 2015 - 12: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 by KingofGamesYami, 27 September 2015 - 12:47 AM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users