树莓派滚动显示
使用实验板实现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); } }
posted on 2015-07-01 00:15 Jasonzhang398 阅读(455) 评论(0) 编辑 收藏 举报