aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Odersky <jodersky@gmail.com>2015-04-22 16:00:15 +0200
committerJakob Odersky <jodersky@gmail.com>2015-04-22 16:00:15 +0200
commitc3e16cf54902089be6792774fd2aba48a846d30a (patch)
tree289b9fad47f45d70bba55a070e99818c5590f5e4
parent314fbd73108044a6dee8293775898b886697bebf (diff)
downloadk8055-c3e16cf54902089be6792774fd2aba48a846d30a.tar.gz
k8055-c3e16cf54902089be6792774fd2aba48a846d30a.tar.bz2
k8055-c3e16cf54902089be6792774fd2aba48a846d30a.zip
add sample
-rw-r--r--README.md35
1 files changed, 35 insertions, 0 deletions
diff --git a/README.md b/README.md
index c5e83de..606c25d 100644
--- a/README.md
+++ b/README.md
@@ -8,6 +8,41 @@ This library provides access to the Velleman K8055 USB Experiment Board. While p
- pseudo-querying of a board's output status (see header file documentation for detailed explanation)
- concise and lightweight
+## Example Program
+```c
+#include <stdio.h>
+#include <stdbool.h>
+#include <k8055.h>
+
+int main(int argc, char *argv[]) {
+ k8055_debug(true); //turn on debug information
+ k8055_device* device = NULL; //this will be a pointer to a K8055 board
+
+ int r = k8055_open_device(0, &device); //open device on port 0
+ if (r != 0) return r; //return error code if something went wrong
+
+ k8055_set_digital(device, 0, true); //turn on digital output 0 (the first one)
+ k8055_set_analog(device, 0, 255); //turn on analog output 0 to maximum
+
+ int digital; //initialize variable containing digital input mask
+ int analog0; //initialize variable containing analog input 0
+ int analog1; //initialize variable containing analog input 1
+ int counter0; //initialize variable containing value of counter 0
+ int counter1; //initialize variable containing value of counter 1
+
+ //read current input
+ k8055_get_all_input(device, &digital, &analog0, &analog1, &counter0, &counter1, false);
+
+ //print input
+ printf("k8055 input status\n");
+ printf("digital bitmask: %d\nanalog 0: %d\nanalog 1: %d\ncounter 0: %d\ncounter 1: %d\n",
+ digital, analog0, analog1, counter0, counter1);
+
+ k8055_close_device(device); //close board and free resources
+ return 0;
+}
+```
+
## Requirements
- libusb-1.0
- (doxygen for documentation generation)