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@9:bf2d151b3b6e, 2020-10-19 (annotated)
- Committer:
- matrixmike
- Date:
- Mon Oct 19 00:17:33 2020 +0000
- Revision:
- 9:bf2d151b3b6e
- Parent:
- 8:7a49220aaa22
experimenting with easy classes and objects prior to implementing useful code
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 | 9:bf2d151b3b6e | 35 | class Employee { |
matrixmike | 9:bf2d151b3b6e | 36 | private: |
matrixmike | 9:bf2d151b3b6e | 37 | // Private attribute |
matrixmike | 9:bf2d151b3b6e | 38 | int salary; |
matrixmike | 9:bf2d151b3b6e | 39 | |
matrixmike | 9:bf2d151b3b6e | 40 | public: |
matrixmike | 9:bf2d151b3b6e | 41 | // Setter |
matrixmike | 9:bf2d151b3b6e | 42 | void setSalary(int s) { |
matrixmike | 9:bf2d151b3b6e | 43 | salary = s; |
matrixmike | 9:bf2d151b3b6e | 44 | } |
matrixmike | 9:bf2d151b3b6e | 45 | // Getter |
matrixmike | 9:bf2d151b3b6e | 46 | int getSalary() { |
matrixmike | 9:bf2d151b3b6e | 47 | return salary; |
matrixmike | 9:bf2d151b3b6e | 48 | } |
matrixmike | 9:bf2d151b3b6e | 49 | }; |
matrixmike | 9:bf2d151b3b6e | 50 | |
matrixmike | 8:7a49220aaa22 | 51 | int function(int a) |
matrixmike | 8:7a49220aaa22 | 52 | { |
matrixmike | 8:7a49220aaa22 | 53 | return a; |
matrixmike | 8:7a49220aaa22 | 54 | } |
matrixmike | 8:7a49220aaa22 | 55 | int functionTimesTwo(int a) |
matrixmike | 8:7a49220aaa22 | 56 | { |
matrixmike | 8:7a49220aaa22 | 57 | return a*2; |
matrixmike | 8:7a49220aaa22 | 58 | } |
matrixmike | 8:7a49220aaa22 | 59 | int functionDivideByTwo(int a) |
matrixmike | 8:7a49220aaa22 | 60 | { |
matrixmike | 8:7a49220aaa22 | 61 | return a/2; |
matrixmike | 8:7a49220aaa22 | 62 | } |
matrixmike | 8:7a49220aaa22 | 63 | |
matrixmike | 0:699a0e5dc3ab | 64 | int main() |
matrixmike | 0:699a0e5dc3ab | 65 | { |
matrixmike | 8:7a49220aaa22 | 66 | IntFunctionWithOneParameter functions[] = { |
matrixmike | 8:7a49220aaa22 | 67 | function, |
matrixmike | 8:7a49220aaa22 | 68 | functionTimesTwo, |
matrixmike | 8:7a49220aaa22 | 69 | functionDivideByTwo, |
matrixmike | 9:bf2d151b3b6e | 70 | function |
matrixmike | 8:7a49220aaa22 | 71 | // row1 |
matrixmike | 8:7a49220aaa22 | 72 | // row1(P0_13) row1(P0_13) |
matrixmike | 8:7a49220aaa22 | 73 | }; |
matrixmike | 8:7a49220aaa22 | 74 | |
matrixmike | 9:bf2d151b3b6e | 75 | Employee myObj; |
matrixmike | 9:bf2d151b3b6e | 76 | myObj.setSalary(50000); |
matrixmike | 9:bf2d151b3b6e | 77 | int newSal = myObj.getSalary(); |
matrixmike | 9:bf2d151b3b6e | 78 | |
matrixmike | 8:7a49220aaa22 | 79 | for(int i = 0; i < 3; ++i) { |
matrixmike | 8:7a49220aaa22 | 80 | // cout << functions[i](8) << endl; |
matrixmike | 8:7a49220aaa22 | 81 | functions[i](8); |
matrixmike | 8:7a49220aaa22 | 82 | } |
matrixmike | 0:699a0e5dc3ab | 83 | while(1) { |
matrixmike | 4:0dc3e04090ab | 84 | // for (int cv = 0; cv < 4 ; cv++) { |
matrixmike | 4:0dc3e04090ab | 85 | // myLedBlink(seq[cv]); |
matrixmike | 4:0dc3e04090ab | 86 | // } |
matroxmike | 7:0f62c513f003 | 87 | |
matroxmike | 7:0f62c513f003 | 88 | row3 = 1; |
matrixmike | 0:699a0e5dc3ab | 89 | wait(0.2); |
matroxmike | 7:0f62c513f003 | 90 | row3 = 0; |
matrixmike | 0:699a0e5dc3ab | 91 | wait(0.2); |
matrixmike | 6:83feebd43ec8 | 92 | // ** |
matroxmike | 7:0f62c513f003 | 93 | row2 = 1; |
matrixmike | 5:7881d6e0732f | 94 | wait(0.2); |
matroxmike | 7:0f62c513f003 | 95 | row2 = 0; |
matrixmike | 5:7881d6e0732f | 96 | wait(0.2); |
matrixmike | 6:83feebd43ec8 | 97 | // ** |
matroxmike | 7:0f62c513f003 | 98 | row1 = 1; |
matrixmike | 6:83feebd43ec8 | 99 | wait(0.2); |
matroxmike | 7:0f62c513f003 | 100 | row1 = 0; |
matrixmike | 6:83feebd43ec8 | 101 | wait(0.2); |
matrixmike | 6:83feebd43ec8 | 102 | // ** |
matrixmike | 2:71c7441b477a | 103 | //} |
matrixmike | 2:71c7441b477a | 104 | // for (int cv = 0; cv < 3 ; cv++) { |
matrixmike | 2:71c7441b477a | 105 | // myLedBlink(cv); |
matrixmike | 2:71c7441b477a | 106 | // } |
matrixmike | 0:699a0e5dc3ab | 107 | } |
matroxmike | 7:0f62c513f003 | 108 | } |