libpruio
0.2
Input/Output driver for digital/analog lines on Beagleboard hardware
All
Classes
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
Pages
button.bas
Go to the documentation of this file.
1
/'* \file button.bas
2
\brief Example: get state of a button.
3
4
This file contains an example on how to use libpruio to get the state
5
of a button connetect to a GPIO pin on the beaglebone board. Here pin 7
6
on header P8 is used as input with pullup resistor. Connect the button
7
between P8_07 (GPIO input) and P8_01 (GND).
8
9
Licence: GPLv3
10
11
Copyright 2014 by Thomas{ dOt ]Freiherr[ At ]gmx[ DoT }net
12
13
14
Compile by: `fbc -w all button.bas`
15
16
'/
17
18
' include libpruio
19
#INCLUDE ONCE
"../pruio/pruio.bi"
20
' include the convenience macros for header pins
21
#INCLUDE ONCE
"../pruio/pruio_pins.bi"
22
23
'* The header pin to use.
24
#DEFINE
PIN P8_07
25
26
' ***** main *****
27
28
VAR
io
=
NEW
PruIo
'*< Create a PruIo structure, wakeup devices.
29
30
WITH
*
io
31
DO
32
IF
.Errr
THEN ?
"initialisation failed ("
& *.Errr &
")"
:
EXIT DO
33
34
IF
.Gpio->config(PIN, PRUIO_GPIO_IN_1)
THEN
_
' configure pin
35
?
"pin configuration failed ("
& *.Errr &
")"
:
EXIT DO
36
37
IF
.config()
THEN
_
38
?
"config failed ("
& *.Errr &
")"
:
EXIT DO
39
40
DO
' print current state (until keystroke)
41
?
!
"\r"
& .Gpio->Value(PIN);
42
SLEEP 100
43
LOOP UNTIL LEN
(
INKEY
()) :
?
44
LOOP UNTIL 1
45
IF
.Gpio->config(PIN, PRUIO_PIN_RESET)
THEN
_
' re-configure pin
46
?
"pin re-configuration failed ("
& *.Errr &
")"
47
48
IF
.Errr
THEN ?
"press any key to quit"
:
SLEEP
49
END WITH
50
51
DELETE
io
' reset ADC, PinMux and GPIOs, clear memory
52
53
'' help Doxygen to dokument the main code
54
'&/** The main function. */
55
'&int main() {PruIo::PruIo(); GpioUdt::config(); PruIo::config(); GpioUdt::Value(); PruIo::~PruIo();}
56
src
examples
button.bas
Generated on Sun Oct 26 2014 16:53:02 for libpruio by
1.8.6