Naveen Kumar B
/
led_matrix_smily_STM32L476
led matrix based on max7219 connected to nucleo-l476rg
main.cpp@1:9fa35bcbc634, 2020-10-07 (annotated)
- Committer:
- NaveenKumarB
- Date:
- Wed Oct 07 11:23:59 2020 +0000
- Revision:
- 1:9fa35bcbc634
- Parent:
- 0:f11d86c27d4c
led Smile
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
stek542 | 0:f11d86c27d4c | 1 | #include "max7219.h" |
stek542 | 0:f11d86c27d4c | 2 | |
NaveenKumarB | 1:9fa35bcbc634 | 3 | void printNumber(uint16_t number, uint8_t noOfDigits); |
NaveenKumarB | 1:9fa35bcbc634 | 4 | |
NaveenKumarB | 1:9fa35bcbc634 | 5 | Max7219 max7219(D11, NC, D13, D10);//D11->MOSI - 15(Nucleo), MISO, D13->CLK ->11(Nucleo), D10->CS -17(Nucleo) |
NaveenKumarB | 1:9fa35bcbc634 | 6 | uint8_t numberOfDevices = 4; |
NaveenKumarB | 1:9fa35bcbc634 | 7 | |
stek542 | 0:f11d86c27d4c | 8 | //DigitalOut my_sck(D13); |
NaveenKumarB | 1:9fa35bcbc634 | 9 | |
NaveenKumarB | 1:9fa35bcbc634 | 10 | const unsigned char num1[]= { |
NaveenKumarB | 1:9fa35bcbc634 | 11 | 0x00,0x00,0x00,0x42,0x7F,0x40,0x00,0x00 |
NaveenKumarB | 1:9fa35bcbc634 | 12 | }; //1 |
NaveenKumarB | 1:9fa35bcbc634 | 13 | const unsigned char num2[]= { |
NaveenKumarB | 1:9fa35bcbc634 | 14 | 0x00,0x46,0x61,0x51,0x49,0x46,0x00,0x00 |
NaveenKumarB | 1:9fa35bcbc634 | 15 | }; //2 |
NaveenKumarB | 1:9fa35bcbc634 | 16 | const unsigned char num3[]= { |
NaveenKumarB | 1:9fa35bcbc634 | 17 | 0x00,0x22,0x41,0x49,0x49,0x36,0x00,0x00 |
NaveenKumarB | 1:9fa35bcbc634 | 18 | }; //3 |
NaveenKumarB | 1:9fa35bcbc634 | 19 | const unsigned char num4[]= { |
NaveenKumarB | 1:9fa35bcbc634 | 20 | 0x00,0x0C,0x0A,0x09,0x7F,0x08,0x00,0x00 |
NaveenKumarB | 1:9fa35bcbc634 | 21 | }; //4 |
NaveenKumarB | 1:9fa35bcbc634 | 22 | const unsigned char num5[]= { |
NaveenKumarB | 1:9fa35bcbc634 | 23 | 0x00,0x00,0x4F,0x49,0x49,0x31,0x00,0x00 |
NaveenKumarB | 1:9fa35bcbc634 | 24 | }; //5 |
NaveenKumarB | 1:9fa35bcbc634 | 25 | const unsigned char num6[]= { |
NaveenKumarB | 1:9fa35bcbc634 | 26 | 0x00,0x00,0x3C,0x4A,0x49,0x30,0x00,0x00 |
NaveenKumarB | 1:9fa35bcbc634 | 27 | }; //6 |
NaveenKumarB | 1:9fa35bcbc634 | 28 | const unsigned char num7[]= { |
NaveenKumarB | 1:9fa35bcbc634 | 29 | 0x00,0x00,0x61,0x11,0x09,0x07,0x00,0x00 |
NaveenKumarB | 1:9fa35bcbc634 | 30 | }; //7 |
NaveenKumarB | 1:9fa35bcbc634 | 31 | const unsigned char num8[]= { |
NaveenKumarB | 1:9fa35bcbc634 | 32 | 0x00,0x00,0x36,0x49,0x49,0x36,0x00,0x00 |
NaveenKumarB | 1:9fa35bcbc634 | 33 | }; //8 |
NaveenKumarB | 1:9fa35bcbc634 | 34 | const unsigned char num9[]= { |
NaveenKumarB | 1:9fa35bcbc634 | 35 | 0x00,0x00,0x06,0x49,0x49,0x3E,0x00,0x00 |
NaveenKumarB | 1:9fa35bcbc634 | 36 | }; //9 |
NaveenKumarB | 1:9fa35bcbc634 | 37 | const unsigned char num0[]= { |
NaveenKumarB | 1:9fa35bcbc634 | 38 | 0x00,0x00,0x3E,0x41,0x41,0x3E,0x00,0x00 |
NaveenKumarB | 1:9fa35bcbc634 | 39 | }; //0 |
NaveenKumarB | 1:9fa35bcbc634 | 40 | |
NaveenKumarB | 1:9fa35bcbc634 | 41 | uint8_t smiley[] = {0x3c, 0x42, 0x81,0xA5, 0x81, 0xA5, 0x5A, 0x3C}; |
NaveenKumarB | 1:9fa35bcbc634 | 42 | uint8_t numberFont[10][8] = { |
NaveenKumarB | 1:9fa35bcbc634 | 43 | 0x18,0x24,0x24,0x24,0x24,0x24,0x18,0x00,//0 |
NaveenKumarB | 1:9fa35bcbc634 | 44 | 0x08,0x18,0x08,0x08,0x08,0x08,0x1C,0x00,//1 |
NaveenKumarB | 1:9fa35bcbc634 | 45 | 0x38,0x44,0x44,0x08,0x10,0x20,0x7C,0x00,//2 |
NaveenKumarB | 1:9fa35bcbc634 | 46 | 0x38,0x44,0x04,0x18,0x04,0x44,0x38,0x00,//3 |
NaveenKumarB | 1:9fa35bcbc634 | 47 | 0x18,0x28,0x48,0x7C,0x08,0x08,0x08,0x00,//4 |
NaveenKumarB | 1:9fa35bcbc634 | 48 | 0x3C,0x20,0x20,0x38,0x04,0x04,0x38,0x00,//5 |
NaveenKumarB | 1:9fa35bcbc634 | 49 | 0x08,0x10,0x20,0x38,0x24,0x24,0x18,0x00,//6 |
NaveenKumarB | 1:9fa35bcbc634 | 50 | |
NaveenKumarB | 1:9fa35bcbc634 | 51 | 0x3C,0x04,0x04,0x08,0x10,0x20,0x20,0x00,//7 |
NaveenKumarB | 1:9fa35bcbc634 | 52 | 0x18,0x24,0x24,0x18,0x24,0x24,0x18,0x00,//8 |
NaveenKumarB | 1:9fa35bcbc634 | 53 | 0x18,0x24,0x24,0x1C,0x04,0x04,0x18,0x00,//9 |
NaveenKumarB | 1:9fa35bcbc634 | 54 | }; |
NaveenKumarB | 1:9fa35bcbc634 | 55 | |
stek542 | 0:f11d86c27d4c | 56 | int main() |
stek542 | 0:f11d86c27d4c | 57 | { |
NaveenKumarB | 1:9fa35bcbc634 | 58 | uint8_t col = 0; |
NaveenKumarB | 1:9fa35bcbc634 | 59 | uint8_t row = 0; |
NaveenKumarB | 1:9fa35bcbc634 | 60 | |
NaveenKumarB | 1:9fa35bcbc634 | 61 | max7219.set_num_devices(numberOfDevices); |
stek542 | 0:f11d86c27d4c | 62 | |
stek542 | 0:f11d86c27d4c | 63 | max7219_configuration_t cfg = { |
stek542 | 0:f11d86c27d4c | 64 | .device_number = 1, |
stek542 | 0:f11d86c27d4c | 65 | .decode_mode = 0, |
stek542 | 0:f11d86c27d4c | 66 | .intensity = Max7219::MAX7219_INTENSITY_3, |
stek542 | 0:f11d86c27d4c | 67 | .scan_limit = Max7219::MAX7219_SCAN_8 |
stek542 | 0:f11d86c27d4c | 68 | }; |
NaveenKumarB | 1:9fa35bcbc634 | 69 | wait_ms(100); |
NaveenKumarB | 1:9fa35bcbc634 | 70 | max7219.init_display(cfg); |
NaveenKumarB | 1:9fa35bcbc634 | 71 | wait_ms(100); |
NaveenKumarB | 1:9fa35bcbc634 | 72 | // max7219.enable_device(2); |
NaveenKumarB | 1:9fa35bcbc634 | 73 | // max7219.enable_device(2); |
NaveenKumarB | 1:9fa35bcbc634 | 74 | max7219.enable_display(); |
NaveenKumarB | 1:9fa35bcbc634 | 75 | // max7219.set_display_test(); |
NaveenKumarB | 1:9fa35bcbc634 | 76 | wait_ms(100); |
stek542 | 0:f11d86c27d4c | 77 | |
NaveenKumarB | 1:9fa35bcbc634 | 78 | // max7219.write_digit(1,1,0b00111100); |
NaveenKumarB | 1:9fa35bcbc634 | 79 | // max7219.write_digit(1,2,0b01000010); |
NaveenKumarB | 1:9fa35bcbc634 | 80 | // max7219.write_digit(1,3,0b10000001); |
NaveenKumarB | 1:9fa35bcbc634 | 81 | // max7219.write_digit(1,4,0b10100101); |
NaveenKumarB | 1:9fa35bcbc634 | 82 | // max7219.write_digit(1,5,0b10000001); |
NaveenKumarB | 1:9fa35bcbc634 | 83 | // max7219.write_digit(1,6,0b10100101); |
NaveenKumarB | 1:9fa35bcbc634 | 84 | // max7219.write_digit(1,7,0b01011010); |
NaveenKumarB | 1:9fa35bcbc634 | 85 | // max7219.write_digit(1,8,0b00111100); |
stek542 | 0:f11d86c27d4c | 86 | |
NaveenKumarB | 1:9fa35bcbc634 | 87 | // max7219.write_digit(2,1,0b00111100); |
NaveenKumarB | 1:9fa35bcbc634 | 88 | // max7219.write_digit(2,2,0b01000010); |
NaveenKumarB | 1:9fa35bcbc634 | 89 | // max7219.write_digit(2,3,0b10000001); |
NaveenKumarB | 1:9fa35bcbc634 | 90 | // max7219.write_digit(2,4,0b10100101); |
NaveenKumarB | 1:9fa35bcbc634 | 91 | // max7219.write_digit(2,5,0b10000001); |
NaveenKumarB | 1:9fa35bcbc634 | 92 | // max7219.write_digit(2,6,0b10100101); |
NaveenKumarB | 1:9fa35bcbc634 | 93 | // max7219.write_digit(2,7,0b01011010); |
NaveenKumarB | 1:9fa35bcbc634 | 94 | // max7219.write_digit(2,8,0b00111100); |
NaveenKumarB | 1:9fa35bcbc634 | 95 | |
NaveenKumarB | 1:9fa35bcbc634 | 96 | max7219.write_digit(3,1,0b00111100); |
NaveenKumarB | 1:9fa35bcbc634 | 97 | max7219.write_digit(3,2,0b01000010); |
NaveenKumarB | 1:9fa35bcbc634 | 98 | max7219.write_digit(3,3,0b10000001); |
NaveenKumarB | 1:9fa35bcbc634 | 99 | max7219.write_digit(3,4,0b10100101); |
NaveenKumarB | 1:9fa35bcbc634 | 100 | max7219.write_digit(3,5,0b10000001); |
NaveenKumarB | 1:9fa35bcbc634 | 101 | max7219.write_digit(3,6,0b10100101); |
NaveenKumarB | 1:9fa35bcbc634 | 102 | max7219.write_digit(3,7,0b01011010); |
NaveenKumarB | 1:9fa35bcbc634 | 103 | max7219.write_digit(3,8,0b00111100); |
NaveenKumarB | 1:9fa35bcbc634 | 104 | wait_ms(2000); |
NaveenKumarB | 1:9fa35bcbc634 | 105 | |
NaveenKumarB | 1:9fa35bcbc634 | 106 | max7219.device_all_on(1); |
NaveenKumarB | 1:9fa35bcbc634 | 107 | |
NaveenKumarB | 1:9fa35bcbc634 | 108 | wait_ms(2000); |
NaveenKumarB | 1:9fa35bcbc634 | 109 | |
NaveenKumarB | 1:9fa35bcbc634 | 110 | max7219.device_all_off(1); |
NaveenKumarB | 1:9fa35bcbc634 | 111 | wait_ms(2000); |
NaveenKumarB | 1:9fa35bcbc634 | 112 | uint8_t number; |
NaveenKumarB | 1:9fa35bcbc634 | 113 | |
NaveenKumarB | 1:9fa35bcbc634 | 114 | max7219.display_all_off(); |
NaveenKumarB | 1:9fa35bcbc634 | 115 | uint8_t noOfDigits =2; |
NaveenKumarB | 1:9fa35bcbc634 | 116 | |
stek542 | 0:f11d86c27d4c | 117 | while (1) { |
stek542 | 0:f11d86c27d4c | 118 | |
NaveenKumarB | 1:9fa35bcbc634 | 119 | // number = 0; |
NaveenKumarB | 1:9fa35bcbc634 | 120 | // for(col = 1; col <= numberOfDevices; col++) |
NaveenKumarB | 1:9fa35bcbc634 | 121 | // { |
NaveenKumarB | 1:9fa35bcbc634 | 122 | // for(row = 1; row < 9; row++) |
NaveenKumarB | 1:9fa35bcbc634 | 123 | // { |
NaveenKumarB | 1:9fa35bcbc634 | 124 | // max7219.write_digit(col,row,numberFont[number][row-1]); |
NaveenKumarB | 1:9fa35bcbc634 | 125 | // } |
NaveenKumarB | 1:9fa35bcbc634 | 126 | // number++; |
NaveenKumarB | 1:9fa35bcbc634 | 127 | // wait_ms(2000); |
NaveenKumarB | 1:9fa35bcbc634 | 128 | // max7219.device_all_off(col); |
NaveenKumarB | 1:9fa35bcbc634 | 129 | // } |
NaveenKumarB | 1:9fa35bcbc634 | 130 | printNumber(12, noOfDigits); |
NaveenKumarB | 1:9fa35bcbc634 | 131 | wait_ms(1000); |
NaveenKumarB | 1:9fa35bcbc634 | 132 | printNumber(345, 3); |
NaveenKumarB | 1:9fa35bcbc634 | 133 | wait_ms(1000); |
NaveenKumarB | 1:9fa35bcbc634 | 134 | printNumber(6789, 4); |
NaveenKumarB | 1:9fa35bcbc634 | 135 | wait_ms(1000); |
NaveenKumarB | 1:9fa35bcbc634 | 136 | printNumber(78, noOfDigits); |
NaveenKumarB | 1:9fa35bcbc634 | 137 | wait_ms(1000); |
NaveenKumarB | 1:9fa35bcbc634 | 138 | printNumber(90, noOfDigits); |
NaveenKumarB | 1:9fa35bcbc634 | 139 | wait_ms(1000); |
stek542 | 0:f11d86c27d4c | 140 | |
stek542 | 0:f11d86c27d4c | 141 | } |
NaveenKumarB | 1:9fa35bcbc634 | 142 | } |
NaveenKumarB | 1:9fa35bcbc634 | 143 | |
NaveenKumarB | 1:9fa35bcbc634 | 144 | void printNumber(uint16_t number, uint8_t noOfDigits) |
NaveenKumarB | 1:9fa35bcbc634 | 145 | { |
NaveenKumarB | 1:9fa35bcbc634 | 146 | uint8_t right, rMiddle, lMiddle, left, col, row; |
NaveenKumarB | 1:9fa35bcbc634 | 147 | max7219.display_all_off(); |
NaveenKumarB | 1:9fa35bcbc634 | 148 | if(noOfDigits == 2) |
NaveenKumarB | 1:9fa35bcbc634 | 149 | { |
NaveenKumarB | 1:9fa35bcbc634 | 150 | right = number%10; |
NaveenKumarB | 1:9fa35bcbc634 | 151 | rMiddle = (uint8_t)(number / 10); |
NaveenKumarB | 1:9fa35bcbc634 | 152 | } |
NaveenKumarB | 1:9fa35bcbc634 | 153 | else if(noOfDigits == 3) |
NaveenKumarB | 1:9fa35bcbc634 | 154 | { |
NaveenKumarB | 1:9fa35bcbc634 | 155 | right = number%10; |
NaveenKumarB | 1:9fa35bcbc634 | 156 | rMiddle = (uint8_t)((number%100)/10); |
NaveenKumarB | 1:9fa35bcbc634 | 157 | lMiddle = (uint8_t)(number/100); |
NaveenKumarB | 1:9fa35bcbc634 | 158 | } |
NaveenKumarB | 1:9fa35bcbc634 | 159 | else if(noOfDigits == 4) |
NaveenKumarB | 1:9fa35bcbc634 | 160 | { |
NaveenKumarB | 1:9fa35bcbc634 | 161 | right = number%10; |
NaveenKumarB | 1:9fa35bcbc634 | 162 | rMiddle = (uint8_t)((number%100)/10); |
NaveenKumarB | 1:9fa35bcbc634 | 163 | lMiddle = (uint8_t)((number%1000)/100); |
NaveenKumarB | 1:9fa35bcbc634 | 164 | left = (uint8_t)(number/1000); |
NaveenKumarB | 1:9fa35bcbc634 | 165 | } |
NaveenKumarB | 1:9fa35bcbc634 | 166 | else if(noOfDigits == 1) |
NaveenKumarB | 1:9fa35bcbc634 | 167 | { |
NaveenKumarB | 1:9fa35bcbc634 | 168 | right = number; |
NaveenKumarB | 1:9fa35bcbc634 | 169 | } |
NaveenKumarB | 1:9fa35bcbc634 | 170 | |
NaveenKumarB | 1:9fa35bcbc634 | 171 | for(col = 1; col <= noOfDigits; col++) |
NaveenKumarB | 1:9fa35bcbc634 | 172 | { |
NaveenKumarB | 1:9fa35bcbc634 | 173 | if(col == 1) |
NaveenKumarB | 1:9fa35bcbc634 | 174 | { |
NaveenKumarB | 1:9fa35bcbc634 | 175 | for(row = 1; row < 9; row++) |
NaveenKumarB | 1:9fa35bcbc634 | 176 | { |
NaveenKumarB | 1:9fa35bcbc634 | 177 | max7219.write_digit(col,row,numberFont[right][row-1]); |
NaveenKumarB | 1:9fa35bcbc634 | 178 | } |
NaveenKumarB | 1:9fa35bcbc634 | 179 | |
NaveenKumarB | 1:9fa35bcbc634 | 180 | } |
NaveenKumarB | 1:9fa35bcbc634 | 181 | if(col == 2) |
NaveenKumarB | 1:9fa35bcbc634 | 182 | { |
NaveenKumarB | 1:9fa35bcbc634 | 183 | for(row = 1; row < 9; row++) |
NaveenKumarB | 1:9fa35bcbc634 | 184 | { |
NaveenKumarB | 1:9fa35bcbc634 | 185 | max7219.write_digit(col,row,numberFont[rMiddle][row-1]); |
NaveenKumarB | 1:9fa35bcbc634 | 186 | } |
NaveenKumarB | 1:9fa35bcbc634 | 187 | |
NaveenKumarB | 1:9fa35bcbc634 | 188 | } |
NaveenKumarB | 1:9fa35bcbc634 | 189 | if(col == 3) |
NaveenKumarB | 1:9fa35bcbc634 | 190 | { |
NaveenKumarB | 1:9fa35bcbc634 | 191 | for(row = 1; row < 9; row++) |
NaveenKumarB | 1:9fa35bcbc634 | 192 | { |
NaveenKumarB | 1:9fa35bcbc634 | 193 | max7219.write_digit(col,row,numberFont[lMiddle][row-1]); |
NaveenKumarB | 1:9fa35bcbc634 | 194 | } |
NaveenKumarB | 1:9fa35bcbc634 | 195 | |
NaveenKumarB | 1:9fa35bcbc634 | 196 | } |
NaveenKumarB | 1:9fa35bcbc634 | 197 | if(col == 4) |
NaveenKumarB | 1:9fa35bcbc634 | 198 | { |
NaveenKumarB | 1:9fa35bcbc634 | 199 | for(row = 1; row < 9; row++) |
NaveenKumarB | 1:9fa35bcbc634 | 200 | { |
NaveenKumarB | 1:9fa35bcbc634 | 201 | max7219.write_digit(col,row,numberFont[left][row-1]); |
NaveenKumarB | 1:9fa35bcbc634 | 202 | } |
NaveenKumarB | 1:9fa35bcbc634 | 203 | |
NaveenKumarB | 1:9fa35bcbc634 | 204 | } |
NaveenKumarB | 1:9fa35bcbc634 | 205 | } |
NaveenKumarB | 1:9fa35bcbc634 | 206 | } |
NaveenKumarB | 1:9fa35bcbc634 | 207 |