daeun

mid

Showing 1 changed file with 54 additions and 12 deletions
...@@ -6,6 +6,10 @@ const int FndSelectPin[6] = { 4, 17, 18, 27, 22, 23 }; ...@@ -6,6 +6,10 @@ const int FndSelectPin[6] = { 4, 17, 18, 27, 22, 23 };
6 const int FndPin[8] = { 6, 12, 13, 16, 19, 20, 26, 21 }; 6 const int FndPin[8] = { 6, 12, 13, 16, 19, 20, 26, 21 };
7 const int FndFont[10] = { 0x3F, 0x06, 0x5B, 0x4F, 0x66, 7 const int FndFont[10] = { 0x3F, 0x06, 0x5B, 0x4F, 0x66,
8 0x6D, 0x7D, 0x07, 0x7F, 0x67 }; 8 0x6D, 0x7D, 0x07, 0x7F, 0x67 };
9 +const int Keypad[3] = { 11,9,10 };
10 +int time = 0;
11 +int data[] = { 0,0,0,0,0,0 };
12 +int state = 2;
9 13
10 void init(){ 14 void init(){
11 int i; 15 int i;
...@@ -21,6 +25,26 @@ void init(){ ...@@ -21,6 +25,26 @@ void init(){
21 pinMode( FndPin[i], OUTPUT ); 25 pinMode( FndPin[i], OUTPUT );
22 digitalWrite( FndPin[i], LOW ); 26 digitalWrite( FndPin[i], LOW );
23 } 27 }
28 + for (i = 0; i < 3; i++)
29 + pinMode(Keypad[i], INPUT);
30 +
31 + if (wiringPiISR(Keypad[1], INT_EDGE_FALLING, &stop) < 0) {
32 + return 1;
33 + }
34 + if (wiringPiISR(Keypad[2], INT_EDGE_FALLING, &reset) < 0) {
35 + return 1;
36 + }
37 +}
38 +int KeypadRead()
39 +{
40 + int i, keypadnum = -1;
41 + for (i = 0; i < 3; i++) {
42 + if (!digitalRead(Keypad[i])) {
43 + state = 1;
44 + keypadnum = i; break;
45 + }
46 + }
47 + return keypadnum;
24 } 48 }
25 void FndSelect(int position){ 49 void FndSelect(int position){
26 int i; 50 int i;
...@@ -48,22 +72,40 @@ void FndDisplay(int position, int num){ ...@@ -48,22 +72,40 @@ void FndDisplay(int position, int num){
48 } 72 }
49 FndSelect(position); 73 FndSelect(position);
50 } 74 }
51 -int main(){ 75 +void timer() {
52 int pos; 76 int pos;
53 - int time=0; 77 + for (pos = 0; pos < 6; pos++) {
78 + FndDisplay(pos, data[pos]);
79 + delay(1);
80 + }
81 +}
82 +void stop() {
83 + timer();
84 + state = 1;
85 +}
86 +void reset() {
87 + time = 0;
88 + state = 2;
89 +}
90 +int main(){
54 init(); 91 init();
55 - unsigned long prevtime=millis(); 92 + if (KeypadRead() == 0) {
56 - while(1){ 93 + state = 0;
57 - unsigned long curtime=millis(); 94 + unsigned long prevtime = millis();
58 - if(curtime-prevtime >= 9){ 95 + while (1) {
59 - prevtime=curtime; 96 + unsigned long curtime = millis();
97 + if (curtime - prevtime >= 9) {
98 + prevtime = curtime;
60 time++; 99 time++;
61 } 100 }
62 - int data[6]={time%10, (time%100)/10, (time%1000)/100, 101 + data[6] = { time % 10, (time % 100) / 10, (time % 1000) / 100,
63 - (time/1000)%10, (time/10000)%10, time/100000}; 102 + (time / 1000) % 10, (time / 10000) % 10, time / 100000 };
64 - for(pos=0;pos<6;pos++){ 103 + timer();
65 - FndDisplay(pos,data[pos]); 104 + }
66 - delay(1); 105 + }
106 + else if (state > 0) {
107 + while (1) {
108 + timer();
67 } 109 }
68 } 110 }
69 return 0; 111 return 0;
......