码迷,mamicode.com
首页 > 其他好文 > 详细

树莓派滚动显示

时间:2015-07-01 06:09:24      阅读:180      评论:0      收藏:0      [点我收藏+]

标签:

使用实验板实现lcd(或者七段数码管)的滚动显示,基本要求:编程控制Lcd(或者七段数码管)能滚动显示程序 中自定义的字符串,并且能够用按钮停止/开始滚动

设计电路:

技术分享

 

实物连接:

技术分享

 

代码:

#include <wiringPi.h>
#include <stdio.h>
#include <stdlib.h>

#define DIGIT1 9
#define DIGIT2 13
#define DIGIT3 12
#define DIGIT4 8
#define BTN0 10
#define BTN1 11

#define true 1

char loop[4][8] =   //the loop-running bar in the left windows
    {
        {1,1,1,1,0,0,1,0},//L
        {0,0,0,1,0,0,1,0},//O
        {1,0,0,1,0,0,1,0},//V
        {0,1,1,1,0,0,0,0}//E
    };

void main() 
{
    int pin;
    //int m = 0, n = 0;
    //int flag = 1;
    int chip = 0;
    int chip0,chip1,chip2,chip3;
    int run = 0;
    unsigned int time0 = 0, time1 = 0;

    if (wiringPiSetup () == -1) //test the install status of wiringPi
    {
        exit (1) ;
    }

    for (pin = 0 ; pin < 8 ; ++pin) 
    {
        pinMode (pin, OUTPUT) ;
        digitalWrite(pin, HIGH);
   }

    pinMode(DIGIT1, OUTPUT);
    pinMode(DIGIT2, OUTPUT);
    pinMode(DIGIT3, OUTPUT);
    pinMode(DIGIT4, OUTPUT);
   // pinMode(BTN0, INPUT); //The start button
    pinMode(BTN1, INPUT); //The stop/stop button

    while (true)
    {
        time1 = millis();

        if (digitalRead(BTN1) && run == 0) 
        {
            puts("Start!");
            run = 1;    //change the running state
           // m = 0;
            //n = 0;
            chip = 0;

            time0 = millis();
        }
        else if (digitalRead(BTN0) && run == 1) 
        {
            puts("Stop!");
            run = 0;
       // chip = m =n = 0;
        }

        if (time1 - time0 >= 300 && run == 1) 
        {
            time0 = time1;
//            printf("%d\n", n);
            //m = ++m % 10;
            //n = ++n % 10;

            chip = ++chip % 4;
            //printf("%d\n", n);
        }

        for (pin = 0; pin < 8; pin++)
        {
            digitalWrite(pin, loop[chip][pin]);
        }
        switch(chip){
            case 0:
            digitalWrite(DIGIT1,1);
            break;
            case 1:
            digitalWrite(DIGIT2,1);
            break;
            case 2:
            digitalWrite(DIGIT3,1);
            break;
            case 3:
            digitalWrite(DIGIT4,1);
            break;
        }
        
        delay(180);
        digitalWrite(DIGIT1,0);
        digitalWrite(DIGIT2,0);
        digitalWrite(DIGIT3,0);
        digitalWrite(DIGIT4,0);
        //delay(30);
    }

}

 

树莓派滚动显示

标签:

原文地址:http://www.cnblogs.com/easy-busy/p/4612159.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!