ok

Dependencies:   mbed

Fork of 00_01LAB_matrix8x8_fig_tetris1 by Andres Cano

Committer:
fabeltranm
Date:
Thu Mar 16 22:53:10 2017 +0000
Revision:
2:414129d953dd
Parent:
1:b732136485e0
Child:
3:4a8de2f71ed0
new snake

Who changed what in which revision?

UserRevisionLine numberNew 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 2:414129d953dd 36 void reset_vcol()
fabeltranm 2:414129d953dd 37 {
fabeltranm 2:414129d953dd 38 for (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 2:414129d953dd 49 reset_vcol();
fabeltranm 2:414129d953dd 50 for (j=0; j<8;j++){
fabeltranm 2:414129d953dd 51 for (i=0; i<8;i++){
fabeltranm 2:414129d953dd 52 if(j % 2 == 0){
fabeltranm 2:414129d953dd 53 if (vcol2[j]==0)
fabeltranm 2:414129d953dd 54 vcol2[j]= 1;
fabeltranm 2:414129d953dd 55 vcol2[j]=3>>i;
fabeltranm 2:414129d953dd 56 }
fabeltranm 2:414129d953dd 57 else{
fabeltranm 2:414129d953dd 58 if (vcol2[j]==0x80)
fabeltranm 2:414129d953dd 59 vcol2[j]= 1;
fabeltranm 2:414129d953dd 60 vcol2[j]=3>>i;
fabeltranm 2:414129d953dd 61 }
fabeltranm 2:414129d953dd 62 printMatrix(vcol2);
fabeltranm 2:414129d953dd 63 wait_ms(5);
fabeltranm 2:414129d953dd 64 }
fabeltranm 2:414129d953dd 65 }
fabeltranm 2:414129d953dd 66 }
fabeltranm 2:414129d953dd 67
fabeltranm 1:b732136485e0 68 void print_Snake()
fabeltranm 1:b732136485e0 69 {
fabeltranm 2:414129d953dd 70
fabeltranm 2:414129d953dd 71 uint8_t vt1[8]={1,3,7,0xf,0x1f,0x3f, 0x7f,0xff};
fabeltranm 2:414129d953dd 72 uint8_t vt2[8]={0b10000000,0b11000000,0b11100000,0b11110000,0b11111000,0b11111100,0b11111110,0b11111111};
fabeltranm 0:61199d9d0aed 73
fabeltranm 2:414129d953dd 74
fabeltranm 1:b732136485e0 75 int j, i;
fabeltranm 2:414129d953dd 76 //reset
fabeltranm 2:414129d953dd 77 reset_vcol();
fabeltranm 1:b732136485e0 78 for (j=0; j<8;j++){
fabeltranm 1:b732136485e0 79 for (i=0; i<8;i++){
fabeltranm 2:414129d953dd 80 if(j % 2 == 0){
fabeltranm 2:414129d953dd 81 vcol2[j]=vt1[i];
fabeltranm 2:414129d953dd 82 }else{
fabeltranm 2:414129d953dd 83 vcol2[j]=vt2[i];
fabeltranm 2:414129d953dd 84 }
fabeltranm 1:b732136485e0 85 printMatrix(vcol2);
fabeltranm 1:b732136485e0 86 wait_ms(5);
fabeltranm 1:b732136485e0 87 }
fabeltranm 1:b732136485e0 88 }
fabeltranm 1:b732136485e0 89 }
fabeltranm 0:61199d9d0aed 90 int main() {
fabeltranm 1:b732136485e0 91 uint8_t vcol[8]={0,0,0,0,0,0,0,0};
fabeltranm 0:61199d9d0aed 92 sendSPI(0x0c,1);
fabeltranm 0:61199d9d0aed 93 sendSPI(0x0F,1);
fabeltranm 1:b732136485e0 94 wait (0.1);
fabeltranm 0:61199d9d0aed 95 sendSPI(0x0f,0);
fabeltranm 1:b732136485e0 96 wait (0.1);
fabeltranm 0:61199d9d0aed 97 int i =0;
fabeltranm 0:61199d9d0aed 98 while(1){
fabeltranm 1:b732136485e0 99 print_Snake();
fabeltranm 0:61199d9d0aed 100 }
fabeltranm 0:61199d9d0aed 101 }
fabeltranm 0:61199d9d0aed 102 // ***************************************************************************
fabeltranm 0:61199d9d0aed 103 // option two: use maz7219 library
fabeltranm 0:61199d9d0aed 104
fabeltranm 0:61199d9d0aed 105 // ***************************************************************************
fabeltranm 0:61199d9d0aed 106 /*
fabeltranm 0:61199d9d0aed 107 Max7219 deviceM(PB_15, PB_14, PB_13, PB_12);
fabeltranm 0:61199d9d0aed 108
fabeltranm 0:61199d9d0aed 109
fabeltranm 0:61199d9d0aed 110 int main() {
fabeltranm 0:61199d9d0aed 111
fabeltranm 0:61199d9d0aed 112 max7219_configuration_t cfg = {
fabeltranm 0:61199d9d0aed 113 .device_number = 1,
fabeltranm 0:61199d9d0aed 114 .decode_mode = 0,
fabeltranm 0:61199d9d0aed 115 .intensity = Max7219::MAX7219_INTENSITY_8,
fabeltranm 0:61199d9d0aed 116 .scan_limit = Max7219::MAX7219_SCAN_8
fabeltranm 0:61199d9d0aed 117 };
fabeltranm 0:61199d9d0aed 118
fabeltranm 0:61199d9d0aed 119 deviceM.init_device(cfg);
fabeltranm 0:61199d9d0aed 120
fabeltranm 0:61199d9d0aed 121 deviceM.enable_device(1);
fabeltranm 0:61199d9d0aed 122
fabeltranm 0:61199d9d0aed 123 deviceM.set_display_test();
fabeltranm 0:61199d9d0aed 124 wait(1);
fabeltranm 0:61199d9d0aed 125 deviceM.clear_display_test();
fabeltranm 0:61199d9d0aed 126 wait(1);
fabeltranm 0:61199d9d0aed 127
fabeltranm 0:61199d9d0aed 128 while(1){
fabeltranm 0:61199d9d0aed 129 deviceM.write_digit(1,8,0b11111111);
fabeltranm 0:61199d9d0aed 130 deviceM.write_digit(1,1,0b01010101);
fabeltranm 0:61199d9d0aed 131 deviceM.write_digit(1,2,0b10101010);
fabeltranm 0:61199d9d0aed 132 deviceM.write_digit(1,3,0b01010101);
fabeltranm 0:61199d9d0aed 133 deviceM.write_digit(1,4,0b10101010);
fabeltranm 0:61199d9d0aed 134 deviceM.write_digit(1,5,0b01010101);
fabeltranm 0:61199d9d0aed 135 deviceM.write_digit(1,6,0b10101010);
fabeltranm 0:61199d9d0aed 136 deviceM.write_digit(1,7,0b01010101);
fabeltranm 0:61199d9d0aed 137 }
fabeltranm 0:61199d9d0aed 138 }
fabeltranm 0:61199d9d0aed 139 */
fabeltranm 0:61199d9d0aed 140