Spark_Ultrasonic/Spark_MultiDigitalPins.ubl
2025-06-01 08:54:24 +03:00

47 lines
1.5 KiB
Plaintext

module Spark_MultiDigitalPins Variables
author 'Fatima Idrees'
version 1 1
description ''
spec ' ' 'RGBLED' 'RGBLED Pin _ R _ G _ B _' 'auto bool bool bool' 17 false false false
spec ' ' 'RGBLED2' 'RGBLED Pin _ R _ G _ B _' 'auto auto auto auto' 17 50 50 50
spec 'r' 'Ultransonic Pin' 'Ultransonic Pin _' 'num' 17
to RGBLED Pin Red Green Blue {
comment 'Created by Fatima Idrees'
digitalWriteOp Pin Red
digitalWriteOp (Pin + 1) Green
digitalWriteOp (Pin + 2) Blue
}
to RGBLED2 Pin Red Green Blue {
comment 'Created by Fatima Idrees'
analogWriteOp Pin Red
analogWriteOp (Pin + 1) Green
analogWriteOp (Pin + 2) Blue
}
to 'Ultransonic Pin' Input {
comment 'Contributed by Joan Guillén and Josep Ferràndiz'
digitalWriteOp (Input + 1) false
waitMicros 2
digitalWriteOp (Input + 1) true
waitMicros 50
digitalWriteOp (Input + 1) false
local 'start' (microsOp)
waitUntil (or (not (digitalReadOp (Input + 2))) (((microsOp) - start) > 23320))
waitUntil (or (digitalReadOp (Input + 2)) (((microsOp) - start) > 23320))
if (((microsOp) - start) > 23320) {
comment 'Distance sensor not ready; return the last distance reading'
return _sr04_last
}
comment 'Pulse sent. Measure time until echo is detected.'
start = (microsOp)
waitUntil (or (not (digitalReadOp (Input + 2))) (((microsOp) - start) > 23320))
_sr04_last = ((10 * ((microsOp) - start)) / 583)
comment 'Leave some time for reverberations to die away.'
waitMillis 10
return _sr04_last
}