-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrotary.c
53 lines (41 loc) · 947 Bytes
/
rotary.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
47
48
49
50
51
52
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <wiringPi.h>
#define RoAPin 0 // GPIO-Pin 17, Pinnummer 11
#define RoBPin 1 // GPIO-Pin 18, Pinnummer 12
unsigned char flag;
unsigned char Last_RoB_Status;
unsigned char Current_RoB_Status;
void rotaryDeal(void)
{
Last_RoB_Status = digitalRead(RoBPin);
while(!digitalRead(RoAPin)){
Current_RoB_Status = digitalRead(RoBPin);
flag = 1;
}
if(flag == 1){
flag = 0;
if((Last_RoB_Status == 0)&&(Current_RoB_Status == 1)){
system("echo \"next\" | nc 127.0.0.1 9294 -N");
}
if((Last_RoB_Status == 1)&&(Current_RoB_Status == 0)){
system("echo \"prev\" | nc 127.0.0.1 9294 -N");
}
}
}
int main(void)
{
if(wiringPiSetup() < 0){
fprintf(stderr, "Unable to setup wiringPi:%s\n",strerror(errno));
return 1;
}
pinMode(RoAPin, INPUT);
pinMode(RoBPin, INPUT);
while(1){
rotaryDeal();
delay(10);
}
return 0;
}