-
Notifications
You must be signed in to change notification settings - Fork 141
Open
Description
Board Type
RaspberryPi3 Model B
Operating System
Ubuntu 24.04.1 LTS
Swift Version
Swift version 5.10.1 (swift-5.10.1-RELEASE)
Target: aarch64-unknown-linux-gnu
Installed from swiftARM as binary
Description
A KY-038 sound sensor's digital output (triggered when a threshold is reached) is connected to GPIO pin 23. The board can run with 3.3-5V supply. I am running it at 5V without pull-up resistors.
I have cobbled this code from several sources. It executes without error but none of the closures are triggered.
import Foundation
import SwiftyGPIO
let gpios = SwiftyGPIO.GPIOs(for:.RaspberryPi3)
var gp = gpios[.P23]!
gp.direction = .IN
gp.bounceTime = 0.5
gp.onRaising{
gpio in
print("Transition to 1, current value:" + String(gpio.value))
}
gp.onFalling{
gpio in
print("Transition to 0, current value:" + String(gpio.value))
}
gp.onChange{
gpio in
gpio.clearListeners()
print("The value changed, current value:" + String(gpio.value))
}
RunLoop.main.run()If I replace the RunLoop.main.run() with:
while true {
print("GPIO.value=\(gp.value)")
}Then I can see the value changing from 0 to 1 appropriately. I have tried changing .pull but this has no effect.
Metadata
Metadata
Assignees
Labels
No labels