zoukankan      html  css  js  c++  java
  • new to arduino~~

    I begin to play with arduino, which can be developped with arduino c ( it resembles c or cpp ).

    my first program is to drive the 7-segment led.

    it is simpler than verilog HDL because it is not the sucky hardware describtion language~~(*^__^*) ~~

    so many sensors can be utilized , it's a cool stuff~

    ps arduino is a open source product~

    here is my code:

    代码
    //设置控制各段的数字IO脚
    int _A=1;
    int _B=2;
    int _C=3;
    int _D=4;
    int _E=5;
    int _F=6;
    int _G=7;
    int _DP=8;
    /*

    _B
    ▕▔▏ _C _A
    ▕▔▏ ====》 _D
    ▔▫ _E _G
    _F _DP
    */

    int NUM_SEG [ 16 ][ 7 ] = {
    {
    1,1,1,0,1,1,1 }, //0
    { 1,0,0,0,0,0,1 }, //1
    { 1,1,0,1,1,1,0 }, //2
    { 1,1,0,1,0,1,1 }, //3
    { 1,0,1,1,0,0,1 }, //4
    { 0,1,1,1,0,1,1 }, //5
    { 0,1,1,1,1,1,1 }, //6
    { 1,1,0,0,0,0,1 }, //7
    { 1,1,1,1,1,1,1 }, //8
    { 1,1,1,1,0,1,1 }, //9
    { 1,1,1,1,1,0,1 }, //a
    { 0,0,1,1,1,1,1 }, //b
    { 0,1,1,0,1,1,0 }, //c
    { 1,0,0,1,1,1,1 }, //d
    { 0,1,1,1,1,1,0 }, //e
    { 0,1,1,1,1,0,0 } //f
    };



    void lit( int segment )
    {
    digitalWrite (segment,LOW);
    }

    void quench ( int segment )
    {
    digitalWrite ( segment,HIGH );
    }

    void set_segment ( int segment , int sta )
    {
    if ( sta == 1 )
    {
    lit ( segment );
    }
    else
    {
    quench ( segment );
    }
    }


    void NumDisplay ( int num , int dp , int time)
    {
    for ( int t = 0 ; t < time ; t++ )
    {
    for ( int i = 0 ; i < 7 ; i++ )
    {
    set_segment ( i
    +1 , NUM_SEG [ num % 16 ][ i ] );
    set_segment ( _DP , dp );
    }

    delay (
    1 );
    }

    }


    void setup()
    {
    int i;//定义变量
    for(i=1;i<=8;i++)
    pinMode(i,OUTPUT);
    //设置4~11引脚为输出模式
    }

    void loop()
    {
    while(1)
    {
    for ( int i = 0 ; i < 16 ; i++ )
    NumDisplay ( i ,
    0 , 500 );
    }
    }
  • 相关阅读:
    网站色彩搭配
    web前端小知识,安书整理的
    java基础
    简单android UI必会
    java学习总结
    java字符常量与字符串常量的区别
    最近的学习
    简单的ps操作
    HTTP协议概述
    ABP 学习 Setting
  • 原文地址:https://www.cnblogs.com/kking/p/1852863.html
Copyright © 2011-2022 走看看