Skip to content

Instantly share code, notes, and snippets.

@danko3
Last active December 10, 2015 18:58
Show Gist options
  • Save danko3/4478086 to your computer and use it in GitHub Desktop.
Save danko3/4478086 to your computer and use it in GitHub Desktop.
Example for using the Velleman K8055 USB experiment board.
/*
Example for using the Velleman K8055 USB experiment board.
https://en.wikipedia.org/wiki/Velleman
Using AHK for controlling the board is amazingly simple.
(It is the first time I used dll calls.)
Even AHK newbys can use it and experiment.
Tested on WindowsXP and Window7 32bit.
The library won't load on Windows7 64bit.
I don't know why. Anyone?
*/
#NoEnv
SetWorkingDir, %A_ScriptDir%
; all levels between 0-255
AnalogOutput1 = 12 ; pwm1 (led#9)
AnalogOutput2 = 125 ; pwm2 (led#10)
DigitalOut = 16 ; led #5
hModule := DllCall("LoadLibrary", "str", "k8055d.dll")
if !hModule
{
MsgBox, 4112, Error, loading lib. k8055d.dll
ExitApp
}
; General procedures
; The version is a 32 bit integer.
; It consists of four bytes representing the version.
Version := DllCall("k8055d\Version")
SetFormat, IntegerFast, hex
;MsgBox,k8055.dll Version=%Version%
version := SubStr(version, 3) ; strip 0x
StringReplace, Version, Version, 00,.0,all
MsgBox,k8055.dll `nVersion: %Version%
SetFormat, IntegerFast, d ; back to default format.
dev := DllCall("k8055d\SearchDevices")
if !dev
{
MsgBox, 4112, Error, No P8055 board found!
ExitApp
}
; Analogue to Digital converter procedures
chana := DllCall("k8055d\ReadAnalogChannel", "int", 1)
chanb := DllCall("k8055d\ReadAnalogChannel", "int", 2)
MsgBox, Channel 1 = %chana% `nChannel 2 = %chanb%
;DllCall("k8055d\OutputAnalogChannel", "int", 1, "int", AnalogOutput1)
;DllCall("k8055d\OutputAnalogChannel", "int", 2, "int", AnalogOutput2)
;DllCall("k8055d\OutputAllAnalog", "int", AnalogOutput1, "int", AnalogOutput2)
;DllCall("k8055d\SetAllAnalog")
;DllCall("k8055d\ClearAllAnalog")
; Digital Output procedures
;DllCall("k8055d\SetAllDigital")
;DllCall("k8055d\ClearAllDigital")
; press one or more of the five input buttons.
; button values are 1,2,4,8,16
; (the buttonvalues are added.)
Button := DllCall("k8055d\ReadAllDigital")
MsgBox, You pressed button: %Button%
DllCall("k8055d\WriteAllDigital", "int", DigitalOut)
; Counters
;DllCall("k8055d\SetCounterDebounceTime", "int", 1, "int", 5) ;5ms
Counter1 := DllCall("k8055d\ReadCounter", "int", 1)
MsgBox, Counter1: %Counter1%
;DllCall("k8055d\ResetCounter", "int", 1)
DllCall("k8055d\CloseDevice", "int", 0)
Exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment