-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathraspberryPI_api_wiringPi.cpp
executable file
·38 lines (31 loc) · 1.32 KB
/
raspberryPI_api_wiringPi.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <wiringPi.h>
//used PI pins - wiringPI pins
unsigned int controlPins[] = {13,10,11,22,21,7,9,8};
unsigned int inputPins[] = {0,27,16,15,23,26,14,12};
unsigned int outputPins[] = {6,5,4,3,29,28,24,1};
bool GPIO_direction(int pinNumber, int direction){
pinMode(pinNumber, direction);
return true;
}
int GPIO_read(int pinNumber){ return digitalRead(pinNumber); }
bool GPIO_write(int pinNumber, int value){
digitalWrite(pinNumber, value);
return true;
}
bool setUpPins(){
if(wiringPiSetup() == -1){ exit(1); }
//set direction of control pins
for(unsigned int a = 0; a < (sizeof(controlPins)/sizeof(*controlPins)); a++){
if( !GPIO_direction(controlPins[a],1) ){ std::cout << "- error: could not set direction of control pin: " << a << std::endl; return false; }
}
//set direction of input pins
for(unsigned int a = 0; a < (sizeof(inputPins)/sizeof(*inputPins)); a++){
if( !GPIO_direction(inputPins[a],1) ){ std::cout << "- error: could not set direction of input pin: " << a << std::endl; return false; }
}
//set direction of output pins
for(unsigned int a = 0; a < (sizeof(outputPins)/sizeof(*outputPins)); a++){
if( !GPIO_direction(outputPins[a],0) ){ std::cout << "- error: could not set direction of output pin: " << a << std::endl; return false; }
}
return true;
}
bool shutDownPins(){ return true; }