Michael Hewitt / Mbed 2 deprecated microbit_serialDisplay

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 /*
00003  * All the LEDs on the micro:bit are part of the LED Matrix,
00004  * In order to get simple blinking behaviour, we set column 0
00005  * to be permanently at ground. If you want to use the LEDs as
00006  * a screen, there is a display driver in the micro:bit 'DAL',
00007  */
00008 // 21 Oct 2019
00009 /*int seq[5] =   {P0_15,P0_13,P0_14,P0_11};
00010 void myLedBlink(int led)
00011 {
00012     led = 1;
00013     wait(0.2);
00014     led = 0;
00015     wait(0.2);
00016 }
00017 */
00018 // 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
00019 DigitalOut col1(P0_4,0);
00020 DigitalOut col2(P0_5,0);
00021 DigitalOut col3(P0_6,0);
00022 DigitalOut col4(P0_7,0);
00023 DigitalOut col5(P0_8,0);
00024 DigitalOut col6(P0_9,0);
00025 DigitalOut col7(P0_10,0);
00026 DigitalOut col8(P0_11,0);
00027 DigitalOut col9(P0_12,0);
00028 //DigitalOut row3(P0_15); // something
00029 
00030 DigitalOut row1(P0_13); // something
00031 DigitalOut row2(P0_14); // guessing the layout of the LEDs ATM
00032 DigitalOut row3(P0_15); // something
00033 typedef int (*IntFunctionWithOneParameter) (int a);
00034 
00035 class Employee {
00036   private:
00037     // Private attribute
00038     int salary;
00039 
00040   public:
00041     // Setter
00042     void setSalary(int s) {
00043       salary = s;
00044     }
00045     // Getter
00046     int getSalary() {
00047       return salary;
00048     }
00049 };
00050 
00051 int function(int a)
00052 {
00053     return a;
00054 }
00055 int functionTimesTwo(int a)
00056 {
00057     return a*2;
00058 }
00059 int functionDivideByTwo(int a)
00060 {
00061     return a/2;
00062 }
00063 
00064 int main()
00065 {
00066     IntFunctionWithOneParameter functions[] = {
00067         function,
00068         functionTimesTwo,
00069         functionDivideByTwo,
00070         function
00071 //       row1
00072         // row1(P0_13) row1(P0_13)
00073     };
00074 
00075   Employee myObj;
00076   myObj.setSalary(50000);
00077 int newSal = myObj.getSalary();
00078 
00079     for(int i = 0; i < 3; ++i) {
00080 //       cout << functions[i](8) << endl;
00081         functions[i](8);
00082     }
00083     while(1) {
00084 //        for (int cv = 0; cv < 4 ; cv++) {
00085 //           myLedBlink(seq[cv]);
00086 //       }
00087 
00088         row3 = 1;
00089         wait(0.2);
00090         row3 = 0;
00091         wait(0.2);
00092         // **
00093         row2 = 1;
00094         wait(0.2);
00095         row2 = 0;
00096         wait(0.2);
00097         // **
00098         row1 = 1;
00099         wait(0.2);
00100         row1 = 0;
00101         wait(0.2);
00102         // **
00103         //}
00104 //        for (int cv = 0; cv < 3 ; cv++) {
00105 //            myLedBlink(cv);
00106 //        }
00107     }
00108 }