Created
January 3, 2015 14:40
-
-
Save hdurdle/38ea09e349d2626b5d99 to your computer and use it in GitHub Desktop.
Powershell Serial Control of Arduino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Param( | |
[string]$hexColor | |
) | |
if ($hexColor.length -eq 3) { | |
$hexColor = $hexColor.Substring(0,1) * 2 + $hexColor.Substring(1,1) * 2 + $hexColor.Substring(2,1) * 2 | |
} | |
if ($hexColor.length -eq 6) { | |
$r = 0 | |
$g = 0 | |
$b = 0 | |
Try { | |
$r = [System.Convert]::ToByte($hexColor.Substring(0,2),16) | |
$g = [System.Convert]::ToByte($hexColor.Substring(2,2),16) | |
$b = [System.Convert]::ToByte($hexColor.Substring(4,2),16) | |
} | |
Catch {} | |
[Byte[]] $request = 4,$r,$g,$b,10 | |
Write-Host $request | |
$port = new-Object System.IO.Ports.SerialPort COM3,57600,None,8,one | |
#Start-Sleep -s 1 | |
$port.Open() | |
$port.Write($request, 0, $request.Count) | |
$port.Close() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment