Alyson Castiblanco
/
00_01LAB_matrix8x8_fig_tetris
ok
Fork of 00_01LAB_matrix8x8_fig_tetris by
main.cpp@0:61199d9d0aed, 2017-03-15 (annotated)
- Committer:
- fabeltranm
- Date:
- Wed Mar 15 20:45:14 2017 +0000
- Revision:
- 0:61199d9d0aed
- Child:
- 1:b732136485e0
example Matrix8x8 whit SP?
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
fabeltranm | 0:61199d9d0aed | 1 | |
fabeltranm | 0:61199d9d0aed | 2 | #include "mbed.h" |
fabeltranm | 0:61199d9d0aed | 3 | //#include "max7219.h" |
fabeltranm | 0:61199d9d0aed | 4 | |
fabeltranm | 0:61199d9d0aed | 5 | // *************************************************************************** |
fabeltranm | 0:61199d9d0aed | 6 | // option 1 : use SPI |
fabeltranm | 0:61199d9d0aed | 7 | // *************************************************************************** |
fabeltranm | 0:61199d9d0aed | 8 | SPI deviceM(PB_15, PB_14, PB_13); |
fabeltranm | 0:61199d9d0aed | 9 | DigitalOut ssel (PB_12); |
fabeltranm | 0:61199d9d0aed | 10 | |
fabeltranm | 0:61199d9d0aed | 11 | #define uint8_t unsigned char |
fabeltranm | 0:61199d9d0aed | 12 | |
fabeltranm | 0:61199d9d0aed | 13 | uint8_t vcol[8]={0,0,0,0,0,0,0,0}; |
fabeltranm | 0:61199d9d0aed | 14 | |
fabeltranm | 0:61199d9d0aed | 15 | void sendSPI(uint8_t d1, uint8_t d2) |
fabeltranm | 0:61199d9d0aed | 16 | { |
fabeltranm | 0:61199d9d0aed | 17 | deviceM.unlock(); |
fabeltranm | 0:61199d9d0aed | 18 | ssel=0; |
fabeltranm | 0:61199d9d0aed | 19 | deviceM.write(d1); |
fabeltranm | 0:61199d9d0aed | 20 | deviceM.write(d2); |
fabeltranm | 0:61199d9d0aed | 21 | ssel=1; |
fabeltranm | 0:61199d9d0aed | 22 | deviceM.lock(); |
fabeltranm | 0:61199d9d0aed | 23 | }; |
fabeltranm | 0:61199d9d0aed | 24 | |
fabeltranm | 0:61199d9d0aed | 25 | |
fabeltranm | 0:61199d9d0aed | 26 | void printMatrix(uint8_t* vC) |
fabeltranm | 0:61199d9d0aed | 27 | |
fabeltranm | 0:61199d9d0aed | 28 | { |
fabeltranm | 0:61199d9d0aed | 29 | uint8_t i =0; |
fabeltranm | 0:61199d9d0aed | 30 | for (i=1;i<9;i++){ |
fabeltranm | 0:61199d9d0aed | 31 | sendSPI(i,*(vC+i)); |
fabeltranm | 0:61199d9d0aed | 32 | } |
fabeltranm | 0:61199d9d0aed | 33 | |
fabeltranm | 0:61199d9d0aed | 34 | }; |
fabeltranm | 0:61199d9d0aed | 35 | |
fabeltranm | 0:61199d9d0aed | 36 | |
fabeltranm | 0:61199d9d0aed | 37 | int main() { |
fabeltranm | 0:61199d9d0aed | 38 | sendSPI(0x0c,1); |
fabeltranm | 0:61199d9d0aed | 39 | sendSPI(0x0F,1); |
fabeltranm | 0:61199d9d0aed | 40 | wait (1); |
fabeltranm | 0:61199d9d0aed | 41 | sendSPI(0x0f,0); |
fabeltranm | 0:61199d9d0aed | 42 | wait (1); |
fabeltranm | 0:61199d9d0aed | 43 | int i =0; |
fabeltranm | 0:61199d9d0aed | 44 | while(1){ |
fabeltranm | 0:61199d9d0aed | 45 | i ++; |
fabeltranm | 0:61199d9d0aed | 46 | vcol[1]=i; |
fabeltranm | 0:61199d9d0aed | 47 | printMatrix(vcol); |
fabeltranm | 0:61199d9d0aed | 48 | wait(0.5); |
fabeltranm | 0:61199d9d0aed | 49 | } |
fabeltranm | 0:61199d9d0aed | 50 | } |
fabeltranm | 0:61199d9d0aed | 51 | // *************************************************************************** |
fabeltranm | 0:61199d9d0aed | 52 | // option two: use maz7219 library |
fabeltranm | 0:61199d9d0aed | 53 | |
fabeltranm | 0:61199d9d0aed | 54 | // *************************************************************************** |
fabeltranm | 0:61199d9d0aed | 55 | /* |
fabeltranm | 0:61199d9d0aed | 56 | Max7219 deviceM(PB_15, PB_14, PB_13, PB_12); |
fabeltranm | 0:61199d9d0aed | 57 | |
fabeltranm | 0:61199d9d0aed | 58 | |
fabeltranm | 0:61199d9d0aed | 59 | int main() { |
fabeltranm | 0:61199d9d0aed | 60 | |
fabeltranm | 0:61199d9d0aed | 61 | max7219_configuration_t cfg = { |
fabeltranm | 0:61199d9d0aed | 62 | .device_number = 1, |
fabeltranm | 0:61199d9d0aed | 63 | .decode_mode = 0, |
fabeltranm | 0:61199d9d0aed | 64 | .intensity = Max7219::MAX7219_INTENSITY_8, |
fabeltranm | 0:61199d9d0aed | 65 | .scan_limit = Max7219::MAX7219_SCAN_8 |
fabeltranm | 0:61199d9d0aed | 66 | }; |
fabeltranm | 0:61199d9d0aed | 67 | |
fabeltranm | 0:61199d9d0aed | 68 | deviceM.init_device(cfg); |
fabeltranm | 0:61199d9d0aed | 69 | |
fabeltranm | 0:61199d9d0aed | 70 | deviceM.enable_device(1); |
fabeltranm | 0:61199d9d0aed | 71 | |
fabeltranm | 0:61199d9d0aed | 72 | deviceM.set_display_test(); |
fabeltranm | 0:61199d9d0aed | 73 | wait(1); |
fabeltranm | 0:61199d9d0aed | 74 | deviceM.clear_display_test(); |
fabeltranm | 0:61199d9d0aed | 75 | wait(1); |
fabeltranm | 0:61199d9d0aed | 76 | |
fabeltranm | 0:61199d9d0aed | 77 | while(1){ |
fabeltranm | 0:61199d9d0aed | 78 | deviceM.write_digit(1,8,0b11111111); |
fabeltranm | 0:61199d9d0aed | 79 | deviceM.write_digit(1,1,0b01010101); |
fabeltranm | 0:61199d9d0aed | 80 | deviceM.write_digit(1,2,0b10101010); |
fabeltranm | 0:61199d9d0aed | 81 | deviceM.write_digit(1,3,0b01010101); |
fabeltranm | 0:61199d9d0aed | 82 | deviceM.write_digit(1,4,0b10101010); |
fabeltranm | 0:61199d9d0aed | 83 | deviceM.write_digit(1,5,0b01010101); |
fabeltranm | 0:61199d9d0aed | 84 | deviceM.write_digit(1,6,0b10101010); |
fabeltranm | 0:61199d9d0aed | 85 | deviceM.write_digit(1,7,0b01010101); |
fabeltranm | 0:61199d9d0aed | 86 | } |
fabeltranm | 0:61199d9d0aed | 87 | } |
fabeltranm | 0:61199d9d0aed | 88 | */ |
fabeltranm | 0:61199d9d0aed | 89 |