-
Notifications
You must be signed in to change notification settings - Fork 10
/
rpi3.c
46 lines (38 loc) · 891 Bytes
/
rpi3.c
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
39
40
41
42
43
44
45
46
#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#define VIBR_MTR_01 8
#define VIBR_MTR_02 9
void hardwareSetup(){
if(wiringPiSetup() == -1){
exit(-1);
}
// Set which gpio pins are output for vibration motor
pinMode(VIBR_MTR_01,OUTPUT);
pinMode(VIBR_MTR_02,OUTPUT);
}
// Drive motor via gpio output signal
int vibrationStateChange(int motor_state){
if(motor_state == 0){
digitalWrite(VIBR_MTR_01,0);
digitalWrite(VIBR_MTR_02,0);
}
else if(motor_state == 1)
digitalWrite(VIBR_MTR_01,1);
else if(motor_state == 2){
digitalWrite(VIBR_MTR_01,1);
digitalWrite(VIBR_MTR_02,1);
}
else{
fprintf(stderr,"wrong motor_state parameter is reached. Allowed limit is between [0,2]\n Current parameter value is %d\n",motor_state);
return -1;
}
return 0;
}
void reset(){
vibrationStateChange(0);
}
void delayMS(int ms){
delay(ms);
}