这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » DIY与开源设计 » 开源硬件 » SIN210学习笔记__Twinkle LED

共13条 1/2 1 2 跳转至

SIN210学习笔记__Twinkle LED

助工
2015-01-21 01:21:49     打赏




        今天只说话,不发图



目的 ,让LED 闪烁起来





第一个,是让LED1-LED4,按着不同的规律闪烁,LED1每秒闪烁一次,LED2 每两秒闪烁一次 ,LED3没四秒闪烁一次.。。。。。


不说了直接上代码


/*led_twinkle.c*/
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/input.h>
#define LED1         0
#define LED2         1
#define LED3         2
#define LED4         3


int main(int argc, char **argv)
{
    unsigned int count = 0;
    int fdled = -1;
    usleep(500*1000);
    fdled = open("/dev/led",O_RDWR);
    if(fdled<0)
     {  
       printf("Error:Can't open /dev/leds\n");
       return -1;
     } 
    printf("\nThe LEDs start Twinkle\n");
    while(1)
    {
      count++;
      ioctl(fdled, count%2,      LED1);
      ioctl(fdled, (count%4)/2,   LED2);
      ioctl(fdled, (count%8)/4,  LED3);
      ioctl(fdled, (count%16)/8, LED4);
      usleep(500*1000); 
    }
   return 0;
}


Makefile如下;
Exec := led_twinkle
Obj := led_twinkle.c
CC := arm-linux-gcc

$(Exec) : $(Obj)
        $(CC) -o $@ $(Obj) $(LDLIBS$(LDLIBS-$(@)))

clean:
        rm -vf $(Exec) *.elf *.o








第二个就是呼吸灯了,,嘿嘿。。。用普通的GPIO口来模拟PWM。





/*respiration_lamp.c*/
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <linux/input.h>

#define LED_ON  0
#define LED_OFF 1

#define LED1    0
#define LED2    1
#define LED3    2
#define LED4    3

#define MAX 100
int main(int argc, char **argv)
{
    unsigned int count = 0;
    int fdled = -1;
    usleep(500*1000);
    fdled = open("/dev/led",O_RDWR);
    if(fdled<0)
     {
       printf("Error:Can't open /dev/leds\n");
       return -1;
     }
    printf("\nRespiration Lamp\n");
    while(1)
    {
      count = 0;
      while(++count < MAX)
   {
        ioctl(fdled, LED_ON, LED1);
        usleep((MAX-count)*100);
        ioctl(fdled,LED_OFF, LED1);
        usleep(count*100);
      }
      usleep(1000*1000);

      count = 0;
      while(++count < MAX)
      {
       ioctl(fdled,LED_OFF,LED1);
       usleep((MAX-count)*100);
       ioctl(fdled,LED_ON, LED1);
       usleep(count*100);
      }
      usleep(1000*1000);
   }
   return 0;

/***********************/

Makefile如下:
Exec := respiration_lamp
Obj := respiration_lamp.c
CC := arm-linux-gcc

$(Exec) : $(Obj)
        $(CC) -o $@ $(Obj) $(LDLIBS$(LDLIBS-$(@)))

clean:
        rm -vf $(Exec) *.elf *.o
                                      

 



编译生存可执行文件之后,运行就可以看到效果了。。这个程序一直是在循环中如果想推出,请 ctrl + C



LED,真是个神奇的东西,下次继续闪灯,,Twinkle,Twinkle,Twinkle....







关键词: sin210学习笔记    

助工
2015-01-21 09:01:07     打赏
2楼
大赞哇,Makefile都啦,就是任性!

助工
2015-01-21 09:49:46     打赏
3楼
楼主加油

助工
2015-01-21 10:46:35     打赏
4楼
其实是官方给的教程详细。。。。。

助工
2015-01-21 10:47:21     打赏
5楼
都是在学你们提供的资料,发现你们给的东西太详细了。学习linux用这个开发板,太赞了。。。

院士
2015-01-21 21:02:49     打赏
6楼

这是真的吗?

看来我是错过一次很好的学习机会啊~~


助工
2015-01-21 23:37:58     打赏
7楼

真的,这个板子真的用来学东西超级好,深入简出。我寒假要是把东西,做玩了,可以把板子寄给你玩玩。

以后三期都是android,就只能给高手用了。编译系统很吃力。

前两天我编译android 4.2 的系统,整整跑了三个半小时(电脑配置 双核 2.6GHz,4G RAM)。磁盘被吃了30G。。。


院士
2015-01-21 23:56:59     打赏
8楼
没有编译过。不过,听说过很慢的样子。

专家
2015-01-22 08:57:22     打赏
9楼
赞一个

助工
2015-01-22 10:09:44     打赏
10楼

android玩好了不容易啊!



共13条 1/2 1 2 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]