7 Segment disp

Dependencies:   mbed

Committer:
psahay
Date:
Thu Jan 29 22:45:45 2015 +0000
Revision:
0:288c00e3c1ae
Lab1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
psahay 0:288c00e3c1ae 1 #include "mbed.h"
psahay 0:288c00e3c1ae 2
psahay 0:288c00e3c1ae 3 InterruptIn pound(p25);
psahay 0:288c00e3c1ae 4 DigitalOut myled(LED1);
psahay 0:288c00e3c1ae 5 DigitalOut dot(p20);
psahay 0:288c00e3c1ae 6 DigitalOut dash(p19);
psahay 0:288c00e3c1ae 7
psahay 0:288c00e3c1ae 8 Timer t1;
psahay 0:288c00e3c1ae 9 Timer t2;
psahay 0:288c00e3c1ae 10
psahay 0:288c00e3c1ae 11 Serial pc(USBTX, USBRX);
psahay 0:288c00e3c1ae 12
psahay 0:288c00e3c1ae 13 void pPress () {
psahay 0:288c00e3c1ae 14 t2.stop();
psahay 0:288c00e3c1ae 15 if(t2.read_ms() > 400) {
psahay 0:288c00e3c1ae 16 dot = 1;
psahay 0:288c00e3c1ae 17 dash= 1;
psahay 0:288c00e3c1ae 18 pc.printf(" ");
psahay 0:288c00e3c1ae 19 }
psahay 0:288c00e3c1ae 20 t1.start();
psahay 0:288c00e3c1ae 21 myled = 1;
psahay 0:288c00e3c1ae 22
psahay 0:288c00e3c1ae 23 }
psahay 0:288c00e3c1ae 24 void pRelease() {
psahay 0:288c00e3c1ae 25 t1.stop();
psahay 0:288c00e3c1ae 26 if(t1.read_ms() > 30 && t1.read_ms() <= 200){
psahay 0:288c00e3c1ae 27 dot = 0;
psahay 0:288c00e3c1ae 28 pc.printf(".");
psahay 0:288c00e3c1ae 29 }
psahay 0:288c00e3c1ae 30 else if (t1.read_ms() > 200) {
psahay 0:288c00e3c1ae 31 //dash= 0;
psahay 0:288c00e3c1ae 32 pc.printf("-");
psahay 0:288c00e3c1ae 33 }
psahay 0:288c00e3c1ae 34 wait(0.1);
psahay 0:288c00e3c1ae 35 t1.reset();
psahay 0:288c00e3c1ae 36 t2.reset();
psahay 0:288c00e3c1ae 37
psahay 0:288c00e3c1ae 38 dot = 1;
psahay 0:288c00e3c1ae 39 //dash = 1;
psahay 0:288c00e3c1ae 40 myled = 0;
psahay 0:288c00e3c1ae 41
psahay 0:288c00e3c1ae 42 t2.start();
psahay 0:288c00e3c1ae 43 }
psahay 0:288c00e3c1ae 44 int main() {
psahay 0:288c00e3c1ae 45 dot=1;
psahay 0:288c00e3c1ae 46 dash=1;
psahay 0:288c00e3c1ae 47 myled = 0;
psahay 0:288c00e3c1ae 48 pound.rise(&pPress);
psahay 0:288c00e3c1ae 49 pound.fall(&pRelease);
psahay 0:288c00e3c1ae 50 t2.start();
psahay 0:288c00e3c1ae 51 while(1) {
psahay 0:288c00e3c1ae 52 if(t1.read_ms()> 200) {
psahay 0:288c00e3c1ae 53 dash = 0;
psahay 0:288c00e3c1ae 54 wait(0.1);
psahay 0:288c00e3c1ae 55 dash = 1;
psahay 0:288c00e3c1ae 56 }
psahay 0:288c00e3c1ae 57 }
psahay 0:288c00e3c1ae 58 }