File tree Expand file tree Collapse file tree 1 file changed +16
-17
lines changed Expand file tree Collapse file tree 1 file changed +16
-17
lines changed Original file line number Diff line number Diff line change 16
16
*/
17
17
#include " mbed.h"
18
18
19
+ #define ROW_COUNT 5
20
+ #define COL_COUNT 5
21
+
19
22
#if defined(MICROBIT_TARGET)
20
23
// Main micro:bit target has access to the LED matrix and on-board features
21
- DigitalOut rows[5 ] = {
24
+ DigitalOut rows[ROW_COUNT ] = {
22
25
DigitalOut (ROW_1, 0 ),
23
26
DigitalOut (ROW_2, 0 ),
24
27
DigitalOut (ROW_3, 0 ),
25
28
DigitalOut (ROW_4, 0 ),
26
29
DigitalOut (ROW_5, 0 )
27
30
};
28
- DigitalOut cols[5 ] = {
31
+ DigitalOut cols[COL_COUNT ] = {
29
32
DigitalOut (COL_1, 1 ),
30
33
DigitalOut (COL_2, 1 ),
31
34
DigitalOut (COL_3, 1 ),
32
35
DigitalOut (COL_4, 1 ),
33
36
DigitalOut (COL_5, 1 )
34
37
};
35
- bool led1;
36
- bool led2;
38
+ bool led1 = false ;
39
+ bool led2 = false ;
37
40
#else
38
41
// The nRF52833 DK and micro:bit V2.2 IF MCU have access to direct LEDs
39
- bool rows[5 ];
40
- bool cols[5 ];
42
+ bool rows[ROW_COUNT ];
43
+ bool cols[COL_COUNT ];
41
44
DigitalOut led1 (LED1, 0 );
42
45
DigitalOut led2 (LED2, 1 );
43
46
#endif
44
47
45
48
int main (void ) {
46
49
// Infinite loop to blink the matrix LEDs if built for the target MCU or
47
- // to toggle the orange and red USB LEDs if built for the interface MCU
50
+ // to toggle the orange and red USB LEDs if built for the interface MCU
48
51
while (true ) {
49
- for (int i = 0 ; i < 5 ; i++) {
50
- rows[i] = 1 ;
51
- int prev_i = i - 1 ;
52
- if (prev_i < 0 ) prev_i = 4 ;
53
- rows[prev_i] = 0 ;
54
- for (int j = 0 ; j < 5 ; j++) {
55
- cols[j] = 0 ;
56
- int prev_j = j - 1 ;
57
- if (prev_j < 0 ) prev_j = 4 ;
58
- cols[prev_j] = 1 ;
52
+ for (int i = 0 , prev_i = ROW_COUNT - 1 ; i < ROW_COUNT; ++i, prev_i = i - 1 ) {
53
+ rows[i] = true ;
54
+ rows[prev_i] = false ;
55
+ for (int j = 0 , prev_j = COL_COUNT - 1 ; j < COL_COUNT; ++j, prev_j = j - 1 ) {
56
+ cols[j] = false ;
57
+ cols[prev_j] = true ;
59
58
60
59
led1 = !led1;
61
60
led2 = !led2;
You can’t perform that action at this time.
0 commit comments