-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
68 lines (53 loc) · 1.1 KB
/
test.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdio.h>
#include <stdlib.h>
#include "src/bbgpio.h"
#define blueLed 60
#define whiteLed 66
#define buttonPin 44
int pinValue = 0,
result = 0;
int setup();
void loop();
int main(void) {
result = setup();
if (result != 0) {
return 1;
}
while (1) {
loop();
}
unExportPin(blueLed);
unExportPin(buttonPin);
return 0;
}
int setup() {
result = exportPin(blueLed);
if (result) {
perror("blueLed export failed");
return EXIT_FAILURE;
}
result = setDirection(blueLed, OUTPUT);
if (result) {
perror("blueLed set direction failed");
return EXIT_FAILURE;
}
result = exportPin(buttonPin);
if (result) {
perror("buttonPin export failed");
return EXIT_FAILURE;
}
result = setDirection(buttonPin, INPUT);
if (result) {
perror("buttonPin set direction failed");
return EXIT_FAILURE;
}
return 0;
}
void loop() {
if (digitalRead(buttonPin) == 1) {
digitalWrite(blueLed, HIGH);
}
else {
digitalWrite(blueLed, LOW);
}
}