From 0bcfedb77aeca23f2605f38da58d0e65af1f4114 Mon Sep 17 00:00:00 2001 From: Finn Dane Date: Sat, 9 Sep 2023 21:13:58 +0200 Subject: [PATCH] adds oscilloscope --- oscilloscope/oscilloscope.lua | 45 +++++++++++++++++++++++++++++++++++ oscilloscope/readme.md | 23 ++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 oscilloscope/oscilloscope.lua create mode 100644 oscilloscope/readme.md 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..30f1dc4 --- /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 +```