to verify the position of the LEDs
This is an attempt to address all the 25 LEDs. This has been done but only on rows. I need to arrange the column calls in some form of array which can be indexed.
main.cpp@8:7a49220aaa22, 2019-10-22 (annotated)
- Committer:
- matrixmike
- Date:
- Tue Oct 22 11:25:52 2019 +0000
- Revision:
- 8:7a49220aaa22
- Parent:
- 7:0f62c513f003
- Child:
- 9:bf2d151b3b6e
added array and assoc for loop - but ineffective
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
matrixmike | 0:699a0e5dc3ab | 1 | #include "mbed.h" |
matrixmike | 0:699a0e5dc3ab | 2 | /* |
matrixmike | 0:699a0e5dc3ab | 3 | * All the LEDs on the micro:bit are part of the LED Matrix, |
matrixmike | 0:699a0e5dc3ab | 4 | * In order to get simple blinking behaviour, we set column 0 |
matrixmike | 0:699a0e5dc3ab | 5 | * to be permanently at ground. If you want to use the LEDs as |
matrixmike | 0:699a0e5dc3ab | 6 | * a screen, there is a display driver in the micro:bit 'DAL', |
matrixmike | 0:699a0e5dc3ab | 7 | */ |
matrixmike | 0:699a0e5dc3ab | 8 | // 21 Oct 2019 |
matrixmike | 8:7a49220aaa22 | 9 | /*int seq[5] = {P0_15,P0_13,P0_14,P0_11}; |
matrixmike | 2:71c7441b477a | 10 | void myLedBlink(int led) |
matrixmike | 2:71c7441b477a | 11 | { |
matrixmike | 2:71c7441b477a | 12 | led = 1; |
matrixmike | 2:71c7441b477a | 13 | wait(0.2); |
matrixmike | 2:71c7441b477a | 14 | led = 0; |
matrixmike | 2:71c7441b477a | 15 | wait(0.2); |
matrixmike | 2:71c7441b477a | 16 | } |
matrixmike | 8:7a49220aaa22 | 17 | */ |
matrixmike | 3:c6d14249d784 | 18 | // https://www.iot-programmer.com/index.php/books/27-micro-bit-iot-in-c/chapters-micro-bit-iot-in-c/54-micro-bit-iot-in-c-the-led-display |
matrixmike | 4:0dc3e04090ab | 19 | DigitalOut col1(P0_4,0); |
matrixmike | 4:0dc3e04090ab | 20 | DigitalOut col2(P0_5,0); |
matrixmike | 3:c6d14249d784 | 21 | DigitalOut col3(P0_6,0); |
matrixmike | 4:0dc3e04090ab | 22 | DigitalOut col4(P0_7,0); |
matrixmike | 4:0dc3e04090ab | 23 | DigitalOut col5(P0_8,0); |
matrixmike | 4:0dc3e04090ab | 24 | DigitalOut col6(P0_9,0); |
matrixmike | 4:0dc3e04090ab | 25 | DigitalOut col7(P0_10,0); |
matrixmike | 4:0dc3e04090ab | 26 | DigitalOut col8(P0_11,0); |
matrixmike | 4:0dc3e04090ab | 27 | DigitalOut col9(P0_12,0); |
matroxmike | 7:0f62c513f003 | 28 | //DigitalOut row3(P0_15); // something |
matrixmike | 4:0dc3e04090ab | 29 | |
matroxmike | 7:0f62c513f003 | 30 | DigitalOut row1(P0_13); // something |
matroxmike | 7:0f62c513f003 | 31 | DigitalOut row2(P0_14); // guessing the layout of the LEDs ATM |
matroxmike | 7:0f62c513f003 | 32 | DigitalOut row3(P0_15); // something |
matrixmike | 8:7a49220aaa22 | 33 | typedef int (*IntFunctionWithOneParameter) (int a); |
matrixmike | 8:7a49220aaa22 | 34 | |
matrixmike | 8:7a49220aaa22 | 35 | int function(int a) |
matrixmike | 8:7a49220aaa22 | 36 | { |
matrixmike | 8:7a49220aaa22 | 37 | return a; |
matrixmike | 8:7a49220aaa22 | 38 | } |
matrixmike | 8:7a49220aaa22 | 39 | int functionTimesTwo(int a) |
matrixmike | 8:7a49220aaa22 | 40 | { |
matrixmike | 8:7a49220aaa22 | 41 | return a*2; |
matrixmike | 8:7a49220aaa22 | 42 | } |
matrixmike | 8:7a49220aaa22 | 43 | int functionDivideByTwo(int a) |
matrixmike | 8:7a49220aaa22 | 44 | { |
matrixmike | 8:7a49220aaa22 | 45 | return a/2; |
matrixmike | 8:7a49220aaa22 | 46 | } |
matrixmike | 8:7a49220aaa22 | 47 | |
matrixmike | 0:699a0e5dc3ab | 48 | int main() |
matrixmike | 0:699a0e5dc3ab | 49 | { |
matrixmike | 8:7a49220aaa22 | 50 | IntFunctionWithOneParameter functions[] = { |
matrixmike | 8:7a49220aaa22 | 51 | function, |
matrixmike | 8:7a49220aaa22 | 52 | functionTimesTwo, |
matrixmike | 8:7a49220aaa22 | 53 | functionDivideByTwo, |
matrixmike | 8:7a49220aaa22 | 54 | // row1 |
matrixmike | 8:7a49220aaa22 | 55 | // row1(P0_13) row1(P0_13) |
matrixmike | 8:7a49220aaa22 | 56 | }; |
matrixmike | 8:7a49220aaa22 | 57 | |
matrixmike | 8:7a49220aaa22 | 58 | for(int i = 0; i < 3; ++i) { |
matrixmike | 8:7a49220aaa22 | 59 | // cout << functions[i](8) << endl; |
matrixmike | 8:7a49220aaa22 | 60 | functions[i](8); |
matrixmike | 8:7a49220aaa22 | 61 | } |
matrixmike | 0:699a0e5dc3ab | 62 | while(1) { |
matrixmike | 4:0dc3e04090ab | 63 | // for (int cv = 0; cv < 4 ; cv++) { |
matrixmike | 4:0dc3e04090ab | 64 | // myLedBlink(seq[cv]); |
matrixmike | 4:0dc3e04090ab | 65 | // } |
matroxmike | 7:0f62c513f003 | 66 | |
matroxmike | 7:0f62c513f003 | 67 | row3 = 1; |
matrixmike | 0:699a0e5dc3ab | 68 | wait(0.2); |
matroxmike | 7:0f62c513f003 | 69 | row3 = 0; |
matrixmike | 0:699a0e5dc3ab | 70 | wait(0.2); |
matrixmike | 6:83feebd43ec8 | 71 | // ** |
matroxmike | 7:0f62c513f003 | 72 | row2 = 1; |
matrixmike | 5:7881d6e0732f | 73 | wait(0.2); |
matroxmike | 7:0f62c513f003 | 74 | row2 = 0; |
matrixmike | 5:7881d6e0732f | 75 | wait(0.2); |
matrixmike | 6:83feebd43ec8 | 76 | // ** |
matroxmike | 7:0f62c513f003 | 77 | row1 = 1; |
matrixmike | 6:83feebd43ec8 | 78 | wait(0.2); |
matroxmike | 7:0f62c513f003 | 79 | row1 = 0; |
matrixmike | 6:83feebd43ec8 | 80 | wait(0.2); |
matrixmike | 6:83feebd43ec8 | 81 | // ** |
matrixmike | 2:71c7441b477a | 82 | //} |
matrixmike | 2:71c7441b477a | 83 | // for (int cv = 0; cv < 3 ; cv++) { |
matrixmike | 2:71c7441b477a | 84 | // myLedBlink(cv); |
matrixmike | 2:71c7441b477a | 85 | // } |
matrixmike | 0:699a0e5dc3ab | 86 | } |
matroxmike | 7:0f62c513f003 | 87 | } |