-
Notifications
You must be signed in to change notification settings - Fork 0
/
ece_231_led_cl.c
44 lines (42 loc) · 1.05 KB
/
ece_231_led_cl.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
// Josh Silva
// 33435438
// Lab4 part 6
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
int main(int argc, const char *argv[])
{
if (argc != 3)
{
printf("Usage:\n");
printf("\tledCtl <led> <on/off>\n");
printf("\n");
printf("<led> : Number between 0-3\n");
printf("<on/off>: 1 = on, 0 = off\n");
return 1;
}
int ledNum = atoi(argv[1]);
if (ledNum < 0 || ledNum > 3)
{
printf("<led> : Number between 0-3\n");
return 1;
}
char ledPath[1024];
sprintf(ledPath, "/sys/class/leds/beaglebone:green:usr%d/brightness",
ledNum); int fid = open(ledPath, O_WRONLY);
int onOff = atoi(argv[2]);
switch (onOff)
{ case 0:
write(fid, "0", 1);
break;
case 1:
write(fid, "1", 1);
break;
default:
printf("<on/off>: 1 = on, 0 = off\n");
return 1;
}
close(fid);
return 0;
}