This program is used to test 2 input switch and 6 output LED (4 normal LED and 2 bi-color LED)

Dependencies:   mbed

Committer:
rito
Date:
Fri Nov 27 10:01:22 2015 +0000
Revision:
0:25100af7d162
Test IO

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rito 0:25100af7d162 1 #include "mbed.h"
rito 0:25100af7d162 2
rito 0:25100af7d162 3 DigitalIn mybutton(USER_BUTTON);
rito 0:25100af7d162 4 DigitalIn switch1(D2);
rito 0:25100af7d162 5 DigitalIn switch2(D3);
rito 0:25100af7d162 6 DigitalOut myled(LED1);
rito 0:25100af7d162 7 DigitalOut red_led1(D4);
rito 0:25100af7d162 8 DigitalOut red_led2(D5);
rito 0:25100af7d162 9 DigitalOut red_led3(D6);
rito 0:25100af7d162 10 DigitalOut red_led4(D7);
rito 0:25100af7d162 11 DigitalOut white_led1a(D8);
rito 0:25100af7d162 12 DigitalOut white_led1b(D9);
rito 0:25100af7d162 13 DigitalOut white_led2a(D10);
rito 0:25100af7d162 14 DigitalOut white_led2b(D11);
rito 0:25100af7d162 15
rito 0:25100af7d162 16 int main()
rito 0:25100af7d162 17 {
rito 0:25100af7d162 18 while(1)
rito 0:25100af7d162 19 {
rito 0:25100af7d162 20 if(switch1 == 0 && switch2 == 0)
rito 0:25100af7d162 21 {
rito 0:25100af7d162 22 red_led1 = 1;
rito 0:25100af7d162 23 wait(0.3);
rito 0:25100af7d162 24 red_led1 = 0;
rito 0:25100af7d162 25 red_led2 = 1;
rito 0:25100af7d162 26 wait(0.3);
rito 0:25100af7d162 27 red_led3 = 1;
rito 0:25100af7d162 28 red_led2 = 0;
rito 0:25100af7d162 29 wait(0.3);
rito 0:25100af7d162 30 red_led3 = 0;
rito 0:25100af7d162 31 red_led4 = 1;
rito 0:25100af7d162 32 wait(0.3);
rito 0:25100af7d162 33 red_led4 = 0;
rito 0:25100af7d162 34 white_led1a = 1;
rito 0:25100af7d162 35 white_led1b = 0;
rito 0:25100af7d162 36 wait(0.3);
rito 0:25100af7d162 37 white_led1a = 0;
rito 0:25100af7d162 38 white_led1b = 1;
rito 0:25100af7d162 39 wait(0.3);
rito 0:25100af7d162 40 white_led1a = 1;
rito 0:25100af7d162 41 white_led1b = 1;
rito 0:25100af7d162 42 wait(0.3);
rito 0:25100af7d162 43 white_led1a = 0;
rito 0:25100af7d162 44 white_led1b = 0;
rito 0:25100af7d162 45 white_led2a = 1;
rito 0:25100af7d162 46 white_led2b = 0;
rito 0:25100af7d162 47 wait(0.3);
rito 0:25100af7d162 48 white_led2a = 0;
rito 0:25100af7d162 49 white_led2b = 1;
rito 0:25100af7d162 50 wait(0.3);
rito 0:25100af7d162 51 white_led2a = 1;
rito 0:25100af7d162 52 white_led2b = 1;
rito 0:25100af7d162 53 wait(0.3);
rito 0:25100af7d162 54 white_led2a = 0;
rito 0:25100af7d162 55 white_led2b = 0;
rito 0:25100af7d162 56 }
rito 0:25100af7d162 57 else if(switch1 == 1 && switch2 == 0)
rito 0:25100af7d162 58 {
rito 0:25100af7d162 59 white_led1a = 0;
rito 0:25100af7d162 60 white_led1b = 0;
rito 0:25100af7d162 61 white_led2a = 0;
rito 0:25100af7d162 62 white_led2b = 0;
rito 0:25100af7d162 63 red_led1 = 0;
rito 0:25100af7d162 64 red_led2 = 0;
rito 0:25100af7d162 65 red_led3 = 0;
rito 0:25100af7d162 66 red_led4 = 0;
rito 0:25100af7d162 67 wait(0.3);
rito 0:25100af7d162 68 red_led1 = 1;
rito 0:25100af7d162 69 red_led2 = 1;
rito 0:25100af7d162 70 red_led3 = 1;
rito 0:25100af7d162 71 red_led4 = 1;
rito 0:25100af7d162 72 wait(0.3);
rito 0:25100af7d162 73 red_led1 = 0;
rito 0:25100af7d162 74 red_led2 = 1;
rito 0:25100af7d162 75 red_led3 = 0;
rito 0:25100af7d162 76 red_led4 = 1;
rito 0:25100af7d162 77 wait(0.3);
rito 0:25100af7d162 78 red_led1 = 1;
rito 0:25100af7d162 79 red_led2 = 0;
rito 0:25100af7d162 80 red_led3 = 1;
rito 0:25100af7d162 81 red_led4 = 0;
rito 0:25100af7d162 82 wait(0.3);
rito 0:25100af7d162 83 red_led1 = 0;
rito 0:25100af7d162 84 red_led2 = 0;
rito 0:25100af7d162 85 red_led3 = 1;
rito 0:25100af7d162 86 red_led4 = 1;
rito 0:25100af7d162 87 wait(0.3);
rito 0:25100af7d162 88 red_led1 = 1;
rito 0:25100af7d162 89 red_led2 = 1;
rito 0:25100af7d162 90 red_led3 = 0;
rito 0:25100af7d162 91 red_led4 = 0;
rito 0:25100af7d162 92 wait(0.3);
rito 0:25100af7d162 93 red_led1 = 0;
rito 0:25100af7d162 94 red_led2 = 1;
rito 0:25100af7d162 95 red_led3 = 1;
rito 0:25100af7d162 96 red_led4 = 0;
rito 0:25100af7d162 97 wait(0.3);
rito 0:25100af7d162 98 red_led1 = 1;
rito 0:25100af7d162 99 red_led2 = 0;
rito 0:25100af7d162 100 red_led3 = 0;
rito 0:25100af7d162 101 red_led4 = 1;
rito 0:25100af7d162 102 wait(0.3);
rito 0:25100af7d162 103 }
rito 0:25100af7d162 104 else if(switch1 == 0 && switch2 == 1)
rito 0:25100af7d162 105 {
rito 0:25100af7d162 106 red_led1 = 0;
rito 0:25100af7d162 107 red_led2 = 0;
rito 0:25100af7d162 108 red_led3 = 0;
rito 0:25100af7d162 109 red_led4 = 0;
rito 0:25100af7d162 110 white_led1a = 1;
rito 0:25100af7d162 111 white_led1b = 1;
rito 0:25100af7d162 112 white_led2a = 1;
rito 0:25100af7d162 113 white_led2b = 1;
rito 0:25100af7d162 114 wait(0.3);
rito 0:25100af7d162 115 white_led1a = 0;
rito 0:25100af7d162 116 white_led1b = 0;
rito 0:25100af7d162 117 white_led2a = 0;
rito 0:25100af7d162 118 white_led2b = 0;
rito 0:25100af7d162 119 wait(0.3);
rito 0:25100af7d162 120 white_led1a = 1;
rito 0:25100af7d162 121 white_led1b = 0;
rito 0:25100af7d162 122 white_led2a = 1;
rito 0:25100af7d162 123 white_led2b = 0;
rito 0:25100af7d162 124 wait(0.3);
rito 0:25100af7d162 125 white_led1a = 0;
rito 0:25100af7d162 126 white_led1b = 1;
rito 0:25100af7d162 127 white_led2a = 0;
rito 0:25100af7d162 128 white_led2b = 1;
rito 0:25100af7d162 129 wait(0.3);
rito 0:25100af7d162 130 white_led1a = 0;
rito 0:25100af7d162 131 white_led1b = 1;
rito 0:25100af7d162 132 white_led2a = 1;
rito 0:25100af7d162 133 white_led2b = 0;
rito 0:25100af7d162 134 wait(0.3);
rito 0:25100af7d162 135 white_led1a = 1;
rito 0:25100af7d162 136 white_led1b = 0;
rito 0:25100af7d162 137 white_led2a = 0;
rito 0:25100af7d162 138 white_led2b = 1;
rito 0:25100af7d162 139 wait(0.3);
rito 0:25100af7d162 140 }
rito 0:25100af7d162 141 else if(switch1 == 0 && switch2 == 0)
rito 0:25100af7d162 142 {
rito 0:25100af7d162 143 red_led1 = 0;
rito 0:25100af7d162 144 red_led2 = 0;
rito 0:25100af7d162 145 red_led3 = 0;
rito 0:25100af7d162 146 red_led4 = 0;
rito 0:25100af7d162 147 white_led1a = 0;
rito 0:25100af7d162 148 white_led1b = 0;
rito 0:25100af7d162 149 white_led2a = 0;
rito 0:25100af7d162 150 white_led2b = 0;
rito 0:25100af7d162 151 }
rito 0:25100af7d162 152 if(myled == 1 && mybutton == 0)
rito 0:25100af7d162 153 {
rito 0:25100af7d162 154 myled = 0;
rito 0:25100af7d162 155 }
rito 0:25100af7d162 156 else if(myled == 0 && mybutton == 0)
rito 0:25100af7d162 157 {
rito 0:25100af7d162 158 myled = 1;
rito 0:25100af7d162 159 }
rito 0:25100af7d162 160 }
rito 0:25100af7d162 161 }