diff --git a/oscilloscope/oscilloscope.lua b/oscilloscope/oscilloscope.lua new file mode 100644 index 0000000..f2924be --- /dev/null +++ b/oscilloscope/oscilloscope.lua @@ -0,0 +1,45 @@ +local side = "right" + +local interval = 0.05 + +local trigger = function(previous, current) + return current > 0 +end + +local mon = peripheral.find("monitor") + +local values = {} +local previous = rs.getAnalogInput(side) +local curr = nil +while true do + os.pullEvent("redstone") + curr = rs.getAnalogInput(side) + if trigger(previous, curr) then break end + previous = curr +end + +values[1] = curr + +mon.setTextScale(0.5) +local monX, monY = mon.getSize() + +print("Triggered!") +for i = 2,monX do + sleep(interval) + values[i] = rs.getAnalogInput(side) +end + +mon.setBackgroundColor(colors.black) +mon.setCursorBlink(false) +mon.clear() + +local prevX = 1 +local prevY = values[1] * (monY-1)/15 +for x, y in pairs(values) do + y = y * (monY-1)/15 + term.redirect(mon) + paintutils.drawLine(prevX, monY-prevY, x, monY-y, colors.green) + term.redirect(term.native()) + prevX = x + prevY = y +end diff --git a/oscilloscope/readme.md b/oscilloscope/readme.md new file mode 100644 index 0000000..27d85e7 --- /dev/null +++ b/oscilloscope/readme.md @@ -0,0 +1,23 @@ +# Oscilloscope +oscilloscope with customizable trigger and polling rate. + +## Setup +1. Open the script in the editor +2. Set the side wich the redstone signal will be read from +3. Set the interval at which the signal will be polled (setting it below 0.05 will not give more resolution as this is the tickspeed) +4. (Optional) Customize the trigger function to trigger when you want it to (see examples below). + +### Example triggers +Trigger when receiving full signal: +```lua +local trigger = function(previous, current) + return current == 15 +end +``` + +Triggers when the difference in the measured signals is more than positive 7: +```lua +local trigger = function(previous, current) + return (current - previous) > 7 +end +```