Skip to content

Instantly share code, notes, and snippets.

@quonic
Created December 27, 2017 17:50
Show Gist options
  • Select an option

  • Save quonic/32d56f1c42bc0a5e5752cd0232aa657c to your computer and use it in GitHub Desktop.

Select an option

Save quonic/32d56f1c42bc0a5e5752cd0232aa657c to your computer and use it in GitHub Desktop.
Talk GPIO via Powershell Core
function Open-GPIOPin ([int]$Pin,[ValidateSet('in','out')][string]$Mode) {
[string]$Pin | Out-File -FilePath "/sys/class/gpio/export" -NoNewline
$Mode | Out-File -FilePath "/sys/class/gpio/gpio$Pin/direction" -NoNewline
}
function Send-GPIOBit ([int]$Pin,[ValidateRange(0,1)][int]$Bit) {
$Bit | Out-File -FilePath "/sys/class/gpio/gpio$Pin/value" -NoNewline
}
function Receive-GPIOBit ([int]$Pin) {
return (Get-Content -Path "/sys/class/gpio/gpio$Pin/value")
}
function Close-GPIOPin ([int]$Pin,[ValidateSet('in','out')][string]$Mode) {
[string]$Pin | Out-File -FilePath "/sys/class/gpio/unexport" -NoNewline
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment