Hubo Library

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
DigitalInput1.cpp
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <unistd.h>
3
4 #include "../hubolib.h"
5 #include "../hubocfg.h" // Required for changing default I2C device.
6
7 using namespace HuboLib;
8
9 /*
10 Compile and link:
11 g++ DigitalInput1.cpp -L../ -lhubo -lpthread -lrt -o DigitalInput1.out
12 Run:
13 sudo ./DigitalInput1.out
14 Purpose:
15 Read digital inputs 0 and 1 and display them in the console.
16 The program will not terminate. Press Ctr-C to exit.
17 */
18
19 int main(void)
20 {
21 // If required - set the I2C device to work with. The Raspberry Pi uses "/dev/i2c-1" which is default, the Banana Pi uses "/dev/i2c-0"
22 #ifdef BPI
23 g_I2CConfig.m_sI2CDevice = "/dev/i2c-0";
24 #endif
25
26 // Initialize the library once in your program.
27 Initialize();
28
29 while (1)
30 {
31 bool bState = false;
32
33 // Read digital input number 0.
34 Get_DI_Channel(0, bState);
35 printf ("Digital input 0 = %s ", bState ? "ON " : "OFF");
36
37 // Read digital input number 1.
38 Get_DI_Channel(1, bState);
39 printf ("Digital input 1 = %s \n", bState ? "ON " : "OFF");
40
41 usleep (1000L * 10L);
42 }
43
44 // We won't get here - press Ctrl-C to terminate.
45 return 0;
46 }
47
HuboLib::I2C_Config::m_sI2CDevice
const char * m_sI2CDevice
Definition: hubocfg.h:48
HuboLib::Initialize
bool Initialize()
Initializes the library.
main
int main(void)
Definition: DigitalInput1.cpp:19
HuboLib::g_I2CConfig
I2C_Config g_I2CConfig
HuboLib::Get_DI_Channel
bool Get_DI_Channel(int channel, bool &bValue)
Retrieves the value of one digital input.
HuboLib
Definition: hubocfg.h:10