adds oscilloscope

This commit is contained in:
Finn Dane 2023-09-09 21:13:58 +02:00
parent c1db32243f
commit 0bcfedb77a
2 changed files with 68 additions and 0 deletions

View File

@ -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

23
oscilloscope/readme.md Normal file
View File

@ -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
```