libpruio
0.0.2
AM33xx-PRU driver for digital input / output and analog input
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:
15
16
fbc -w all button.bas
17
18
'/
19
20
'* include libpruio
21
#INCLUDE ONCE
"../pruio/pruio.bi"
22
'* include the convenience macros for header pins
23
#INCLUDE ONCE
"../pruio/pruio_pins.bi"
24
25
#DEFINE
PIN P8_07
26
27
' ***** main *****
28
29
VAR
io
=
NEW
PruIo
'*< create a PruIo structure, wakeup devices
30
WITH
*
io
31
DO
32
IF
.Errr
THEN ?
"initialisation failed ("
& *.Errr &
")"
:
EXIT DO
33
34
IF
.gpio_set(PIN, PRUIO_IN_1)
THEN
_
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_get(PIN);
42
SLEEP 100
43
LOOP UNTIL LEN
(
INKEY
()) :
?
44
LOOP UNTIL 1
45
IF
.gpio_set(PIN, PRUIO_PIN_RESET)
THEN
_
' re-configure CPU ball
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
src
examples
button.bas
Generated on Fri Jun 6 2014 13:22:54 for libpruio by
1.8.4