test.c
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
char buf[128] = {
0};
int main(int argc, char const *argv[])
{
int fd = -1;
fd = open("/dev/myled", O_RDWR);
if (-1 == fd)
{
perror("open is error\n");
exit(1);
}
while (1)
{
/* printf("请输入'1','2','3'\n");
fgets(buf, sizeof(buf), stdin);
buf[strlen(buf) - 1] = '\0';*/
//led1灯亮灭
buf[0] = '1';
write(fd, buf, sizeof(buf));
sleep(1);
buf[0] = '0';
write(fd, buf, sizeof(buf));
sleep(1);
//led2灯亮灭
buf[0] = '2';
write(fd, buf, sizeof(buf));
sleep(1);
buf[0] = '0';
write(fd, buf, sizeof(buf));
sleep(1);
//led3灯亮灭
buf[0] = '3';
write(fd, buf, sizeof(buf));
sleep(1);
buf[0] = '0';
write(fd, buf, sizeof(buf));
sleep(1);
}