Alyson Castiblanco
/
00_01LAB_matrix8x8_fig_tetris
ok
Fork of 00_01LAB_matrix8x8_fig_tetris by
main.cpp@3:4a8de2f71ed0, 2017-03-16 (annotated)
- Committer:
- fabeltranm
- Date:
- Thu Mar 16 22:56:47 2017 +0000
- Revision:
- 3:4a8de2f71ed0
- Parent:
- 2:414129d953dd
- Child:
- 4:2bc5dfe058ef
snake2 new
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 | 2:414129d953dd | 12 | uint8_t vcol2[8]={0,0,0,0,0,0,0,0}; |
fabeltranm | 1:b732136485e0 | 13 | |
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 | 2:414129d953dd | 35 | |
fabeltranm | 3:4a8de2f71ed0 | 36 | void clr_vcol() |
fabeltranm | 2:414129d953dd | 37 | { |
fabeltranm | 3:4a8de2f71ed0 | 38 | for (int i=0; i<8;i++){ |
fabeltranm | 2:414129d953dd | 39 | vcol2[i]=0; |
fabeltranm | 2:414129d953dd | 40 | } |
fabeltranm | 0:61199d9d0aed | 41 | |
fabeltranm | 2:414129d953dd | 42 | } |
fabeltranm | 2:414129d953dd | 43 | |
fabeltranm | 2:414129d953dd | 44 | void print_Snake2() |
fabeltranm | 2:414129d953dd | 45 | { |
fabeltranm | 2:414129d953dd | 46 | |
fabeltranm | 2:414129d953dd | 47 | int j, i; |
fabeltranm | 2:414129d953dd | 48 | //reset |
fabeltranm | 3:4a8de2f71ed0 | 49 | |
fabeltranm | 2:414129d953dd | 50 | for (j=0; j<8;j++){ |
fabeltranm | 3:4a8de2f71ed0 | 51 | clr_vcol(); |
fabeltranm | 3:4a8de2f71ed0 | 52 | if(j % 2 == 0) |
fabeltranm | 3:4a8de2f71ed0 | 53 | vcol2[j]=1; |
fabeltranm | 3:4a8de2f71ed0 | 54 | else |
fabeltranm | 3:4a8de2f71ed0 | 55 | vcol2[j]=0b10000000; |
fabeltranm | 3:4a8de2f71ed0 | 56 | |
fabeltranm | 2:414129d953dd | 57 | for (i=0; i<8;i++){ |
fabeltranm | 2:414129d953dd | 58 | if(j % 2 == 0){ |
fabeltranm | 3:4a8de2f71ed0 | 59 | vcol2[j]=3<<i; |
fabeltranm | 2:414129d953dd | 60 | } |
fabeltranm | 2:414129d953dd | 61 | else{ |
fabeltranm | 3:4a8de2f71ed0 | 62 | vcol2[j]=0b1100000000>>i; |
fabeltranm | 2:414129d953dd | 63 | } |
fabeltranm | 2:414129d953dd | 64 | printMatrix(vcol2); |
fabeltranm | 2:414129d953dd | 65 | wait_ms(5); |
fabeltranm | 2:414129d953dd | 66 | } |
fabeltranm | 2:414129d953dd | 67 | } |
fabeltranm | 2:414129d953dd | 68 | } |
fabeltranm | 2:414129d953dd | 69 | |
fabeltranm | 1:b732136485e0 | 70 | void print_Snake() |
fabeltranm | 1:b732136485e0 | 71 | { |
fabeltranm | 2:414129d953dd | 72 | |
fabeltranm | 2:414129d953dd | 73 | uint8_t vt1[8]={1,3,7,0xf,0x1f,0x3f, 0x7f,0xff}; |
fabeltranm | 2:414129d953dd | 74 | uint8_t vt2[8]={0b10000000,0b11000000,0b11100000,0b11110000,0b11111000,0b11111100,0b11111110,0b11111111}; |
fabeltranm | 0:61199d9d0aed | 75 | |
fabeltranm | 2:414129d953dd | 76 | |
fabeltranm | 1:b732136485e0 | 77 | int j, i; |
fabeltranm | 2:414129d953dd | 78 | //reset |
fabeltranm | 3:4a8de2f71ed0 | 79 | clr_vcol(); |
fabeltranm | 1:b732136485e0 | 80 | for (j=0; j<8;j++){ |
fabeltranm | 1:b732136485e0 | 81 | for (i=0; i<8;i++){ |
fabeltranm | 2:414129d953dd | 82 | if(j % 2 == 0){ |
fabeltranm | 2:414129d953dd | 83 | vcol2[j]=vt1[i]; |
fabeltranm | 2:414129d953dd | 84 | }else{ |
fabeltranm | 2:414129d953dd | 85 | vcol2[j]=vt2[i]; |
fabeltranm | 2:414129d953dd | 86 | } |
fabeltranm | 1:b732136485e0 | 87 | printMatrix(vcol2); |
fabeltranm | 1:b732136485e0 | 88 | wait_ms(5); |
fabeltranm | 1:b732136485e0 | 89 | } |
fabeltranm | 1:b732136485e0 | 90 | } |
fabeltranm | 1:b732136485e0 | 91 | } |
fabeltranm | 0:61199d9d0aed | 92 | int main() { |
fabeltranm | 1:b732136485e0 | 93 | uint8_t vcol[8]={0,0,0,0,0,0,0,0}; |
fabeltranm | 0:61199d9d0aed | 94 | sendSPI(0x0c,1); |
fabeltranm | 0:61199d9d0aed | 95 | sendSPI(0x0F,1); |
fabeltranm | 1:b732136485e0 | 96 | wait (0.1); |
fabeltranm | 0:61199d9d0aed | 97 | sendSPI(0x0f,0); |
fabeltranm | 1:b732136485e0 | 98 | wait (0.1); |
fabeltranm | 0:61199d9d0aed | 99 | int i =0; |
fabeltranm | 0:61199d9d0aed | 100 | while(1){ |
fabeltranm | 1:b732136485e0 | 101 | print_Snake(); |
fabeltranm | 0:61199d9d0aed | 102 | } |
fabeltranm | 0:61199d9d0aed | 103 | } |
fabeltranm | 0:61199d9d0aed | 104 | // *************************************************************************** |
fabeltranm | 0:61199d9d0aed | 105 | // option two: use maz7219 library |
fabeltranm | 0:61199d9d0aed | 106 | |
fabeltranm | 0:61199d9d0aed | 107 | // *************************************************************************** |
fabeltranm | 0:61199d9d0aed | 108 | /* |
fabeltranm | 0:61199d9d0aed | 109 | Max7219 deviceM(PB_15, PB_14, PB_13, PB_12); |
fabeltranm | 0:61199d9d0aed | 110 | |
fabeltranm | 0:61199d9d0aed | 111 | |
fabeltranm | 0:61199d9d0aed | 112 | int main() { |
fabeltranm | 0:61199d9d0aed | 113 | |
fabeltranm | 0:61199d9d0aed | 114 | max7219_configuration_t cfg = { |
fabeltranm | 0:61199d9d0aed | 115 | .device_number = 1, |
fabeltranm | 0:61199d9d0aed | 116 | .decode_mode = 0, |
fabeltranm | 0:61199d9d0aed | 117 | .intensity = Max7219::MAX7219_INTENSITY_8, |
fabeltranm | 0:61199d9d0aed | 118 | .scan_limit = Max7219::MAX7219_SCAN_8 |
fabeltranm | 0:61199d9d0aed | 119 | }; |
fabeltranm | 0:61199d9d0aed | 120 | |
fabeltranm | 0:61199d9d0aed | 121 | deviceM.init_device(cfg); |
fabeltranm | 0:61199d9d0aed | 122 | |
fabeltranm | 0:61199d9d0aed | 123 | deviceM.enable_device(1); |
fabeltranm | 0:61199d9d0aed | 124 | |
fabeltranm | 0:61199d9d0aed | 125 | deviceM.set_display_test(); |
fabeltranm | 0:61199d9d0aed | 126 | wait(1); |
fabeltranm | 0:61199d9d0aed | 127 | deviceM.clear_display_test(); |
fabeltranm | 0:61199d9d0aed | 128 | wait(1); |
fabeltranm | 0:61199d9d0aed | 129 | |
fabeltranm | 0:61199d9d0aed | 130 | while(1){ |
fabeltranm | 0:61199d9d0aed | 131 | deviceM.write_digit(1,8,0b11111111); |
fabeltranm | 0:61199d9d0aed | 132 | deviceM.write_digit(1,1,0b01010101); |
fabeltranm | 0:61199d9d0aed | 133 | deviceM.write_digit(1,2,0b10101010); |
fabeltranm | 0:61199d9d0aed | 134 | deviceM.write_digit(1,3,0b01010101); |
fabeltranm | 0:61199d9d0aed | 135 | deviceM.write_digit(1,4,0b10101010); |
fabeltranm | 0:61199d9d0aed | 136 | deviceM.write_digit(1,5,0b01010101); |
fabeltranm | 0:61199d9d0aed | 137 | deviceM.write_digit(1,6,0b10101010); |
fabeltranm | 0:61199d9d0aed | 138 | deviceM.write_digit(1,7,0b01010101); |
fabeltranm | 0:61199d9d0aed | 139 | } |
fabeltranm | 0:61199d9d0aed | 140 | } |
fabeltranm | 0:61199d9d0aed | 141 | */ |
fabeltranm | 0:61199d9d0aed | 142 |