-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbuttonPress.ps1
32 lines (29 loc) · 937 Bytes
/
buttonPress.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
Import-Module ./../bin/Debug/netcoreapp2.0/linux-arm/publish/ws281xPowerShell.dll -Force
$LedStripSettings = [PSCustomObject]@{
NumberOfLeds = 21
Brightness = 50
Color = [System.Drawing.Color]::Green
Speed = "Fast"
}
while($true)
{
while((Get-GpioPin -Id 26 -PullMode PullUp).Value -eq 'High')
{
}
$held = 0
while((Get-GpioPin -Id 26 -PullMode PullUp).Value -eq 'Low' -AND $held -lt 10) #lt 10 because each time $held is incremented, 100ms have passed, after 10 iterations, 1 second passed
{
Start-Sleep -Milliseconds 100
++$held
}
if($held -lt 10) #realeased before 1s
{
$LedStripSettings | Set-LedAccrossStrip
}
else # it was pressed at least during 1 second ( might still be being pressed)
{
Write-Host "Button pressed for at least 1 second. "
Set-RainbowCycle -NumberOfLeds $LedStripSettings.NumberOfLeds -Brightness $LedStripSettings.Brightness -NumberOfCycles 1
Start-Sleep -Milliseconds 200
}
}