Dependencies:   mbed

Committer:
leejieun
Date:
Thu Apr 21 08:01:40 2022 +0000
Revision:
0:abb2c73da9d1
7-segmnet mission 3

Who changed what in which revision?

UserRevisionLine numberNew contents of line
leejieun 0:abb2c73da9d1 1 #include "mbed.h"
leejieun 0:abb2c73da9d1 2
leejieun 0:abb2c73da9d1 3 DigitalOut greenLed(LED1);
leejieun 0:abb2c73da9d1 4 BusOut my7Seg(PA_8, PA_9, PA_10, PC_9, PC_8, PC_7, PC_6, PA_11);
leejieun 0:abb2c73da9d1 5 //DigitalIn exButton(PC_11);
leejieun 0:abb2c73da9d1 6
leejieun 0:abb2c73da9d1 7
leejieun 0:abb2c73da9d1 8 DigitalOut inLed(LED1);
leejieun 0:abb2c73da9d1 9 DigitalOut exLed(PA_12);
leejieun 0:abb2c73da9d1 10 DigitalIn inButton(PC_13);
leejieun 0:abb2c73da9d1 11 DigitalIn exButton(PC_11);
leejieun 0:abb2c73da9d1 12
leejieun 0:abb2c73da9d1 13 int main() {
leejieun 0:abb2c73da9d1 14
leejieun 0:abb2c73da9d1 15 my7Seg = 0xFF;
leejieun 0:abb2c73da9d1 16 greenLed = 1;
leejieun 0:abb2c73da9d1 17 int myseg;
leejieun 0:abb2c73da9d1 18 char temp7Seg;
leejieun 0:abb2c73da9d1 19 int n = 0;
leejieun 0:abb2c73da9d1 20 int buffer = 0;
leejieun 0:abb2c73da9d1 21 int preStatus = 0;
leejieun 0:abb2c73da9d1 22 float tempVal = 0;
leejieun 0:abb2c73da9d1 23
leejieun 0:abb2c73da9d1 24 while(1) {
leejieun 0:abb2c73da9d1 25
leejieun 0:abb2c73da9d1 26 if ( 1 == preStatus && 0 == exButton ) {
leejieun 0:abb2c73da9d1 27 inLed = !inLed;
leejieun 0:abb2c73da9d1 28 // buffer = 1;
leejieun 0:abb2c73da9d1 29 n += 1;
leejieun 0:abb2c73da9d1 30 if (n == 6){
leejieun 0:abb2c73da9d1 31 n = 0;
leejieun 0:abb2c73da9d1 32 }
leejieun 0:abb2c73da9d1 33 }
leejieun 0:abb2c73da9d1 34 preStatus = exButton;
leejieun 0:abb2c73da9d1 35
leejieun 0:abb2c73da9d1 36 switch(n) {
leejieun 0:abb2c73da9d1 37 case 0:
leejieun 0:abb2c73da9d1 38 temp7Seg = ~0x77;
leejieun 0:abb2c73da9d1 39 break;
leejieun 0:abb2c73da9d1 40 case 1:
leejieun 0:abb2c73da9d1 41 temp7Seg = ~0x7C;
leejieun 0:abb2c73da9d1 42 break;
leejieun 0:abb2c73da9d1 43 case 2:
leejieun 0:abb2c73da9d1 44 temp7Seg = ~0x39;
leejieun 0:abb2c73da9d1 45 break;
leejieun 0:abb2c73da9d1 46 case 3:
leejieun 0:abb2c73da9d1 47 temp7Seg = ~0x5E;
leejieun 0:abb2c73da9d1 48 break;
leejieun 0:abb2c73da9d1 49 case 4:
leejieun 0:abb2c73da9d1 50 temp7Seg = ~0x79;
leejieun 0:abb2c73da9d1 51 break;
leejieun 0:abb2c73da9d1 52 case 5:
leejieun 0:abb2c73da9d1 53 temp7Seg = ~0x71;
leejieun 0:abb2c73da9d1 54 break;
leejieun 0:abb2c73da9d1 55
leejieun 0:abb2c73da9d1 56 }
leejieun 0:abb2c73da9d1 57 // buffer = 0;
leejieun 0:abb2c73da9d1 58 greenLed = !greenLed;
leejieun 0:abb2c73da9d1 59 my7Seg = (temp7Seg & 0x7F) | ((greenLed & 0x01)<<7);
leejieun 0:abb2c73da9d1 60
leejieun 0:abb2c73da9d1 61 wait(0.25);
leejieun 0:abb2c73da9d1 62
leejieun 0:abb2c73da9d1 63
leejieun 0:abb2c73da9d1 64 }
leejieun 0:abb2c73da9d1 65 }