ok

Dependencies:   mbed

Fork of 00_01LAB_matrix8x8_fig_tetris1 by Andres Cano

Committer:
fabeltranm
Date:
Wed Mar 15 21:47:38 2017 +0000
Revision:
1:b732136485e0
Parent:
0:61199d9d0aed
Child:
2:414129d953dd
matrix8x8

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 0:61199d9d0aed 12
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 0:61199d9d0aed 35
fabeltranm 1:b732136485e0 36 void print_Snake()
fabeltranm 1:b732136485e0 37 {
fabeltranm 1:b732136485e0 38 //reset
fabeltranm 1:b732136485e0 39 uint8_t vcol2[8]={0,0,0,0,0,0,0,0};
fabeltranm 1:b732136485e0 40 uint8_t vcol[8]={0,1,3,7,0xf,0x1f,0x3f,};
fabeltranm 0:61199d9d0aed 41
fabeltranm 1:b732136485e0 42 int j, i;
fabeltranm 1:b732136485e0 43 for (j=0; j<8;j++){
fabeltranm 1:b732136485e0 44 for (i=0; i<8;i++){
fabeltranm 1:b732136485e0 45 vcol2[j]=i;
fabeltranm 1:b732136485e0 46 printMatrix(vcol2);
fabeltranm 1:b732136485e0 47 wait_ms(5);
fabeltranm 1:b732136485e0 48 }
fabeltranm 1:b732136485e0 49 }
fabeltranm 1:b732136485e0 50 }
fabeltranm 0:61199d9d0aed 51 int main() {
fabeltranm 1:b732136485e0 52 uint8_t vcol[8]={0,0,0,0,0,0,0,0};
fabeltranm 0:61199d9d0aed 53 sendSPI(0x0c,1);
fabeltranm 0:61199d9d0aed 54 sendSPI(0x0F,1);
fabeltranm 1:b732136485e0 55 wait (0.1);
fabeltranm 0:61199d9d0aed 56 sendSPI(0x0f,0);
fabeltranm 1:b732136485e0 57 wait (0.1);
fabeltranm 0:61199d9d0aed 58 int i =0;
fabeltranm 0:61199d9d0aed 59 while(1){
fabeltranm 1:b732136485e0 60 print_Snake();
fabeltranm 0:61199d9d0aed 61 }
fabeltranm 0:61199d9d0aed 62 }
fabeltranm 0:61199d9d0aed 63 // ***************************************************************************
fabeltranm 0:61199d9d0aed 64 // option two: use maz7219 library
fabeltranm 0:61199d9d0aed 65
fabeltranm 0:61199d9d0aed 66 // ***************************************************************************
fabeltranm 0:61199d9d0aed 67 /*
fabeltranm 0:61199d9d0aed 68 Max7219 deviceM(PB_15, PB_14, PB_13, PB_12);
fabeltranm 0:61199d9d0aed 69
fabeltranm 0:61199d9d0aed 70
fabeltranm 0:61199d9d0aed 71 int main() {
fabeltranm 0:61199d9d0aed 72
fabeltranm 0:61199d9d0aed 73 max7219_configuration_t cfg = {
fabeltranm 0:61199d9d0aed 74 .device_number = 1,
fabeltranm 0:61199d9d0aed 75 .decode_mode = 0,
fabeltranm 0:61199d9d0aed 76 .intensity = Max7219::MAX7219_INTENSITY_8,
fabeltranm 0:61199d9d0aed 77 .scan_limit = Max7219::MAX7219_SCAN_8
fabeltranm 0:61199d9d0aed 78 };
fabeltranm 0:61199d9d0aed 79
fabeltranm 0:61199d9d0aed 80 deviceM.init_device(cfg);
fabeltranm 0:61199d9d0aed 81
fabeltranm 0:61199d9d0aed 82 deviceM.enable_device(1);
fabeltranm 0:61199d9d0aed 83
fabeltranm 0:61199d9d0aed 84 deviceM.set_display_test();
fabeltranm 0:61199d9d0aed 85 wait(1);
fabeltranm 0:61199d9d0aed 86 deviceM.clear_display_test();
fabeltranm 0:61199d9d0aed 87 wait(1);
fabeltranm 0:61199d9d0aed 88
fabeltranm 0:61199d9d0aed 89 while(1){
fabeltranm 0:61199d9d0aed 90 deviceM.write_digit(1,8,0b11111111);
fabeltranm 0:61199d9d0aed 91 deviceM.write_digit(1,1,0b01010101);
fabeltranm 0:61199d9d0aed 92 deviceM.write_digit(1,2,0b10101010);
fabeltranm 0:61199d9d0aed 93 deviceM.write_digit(1,3,0b01010101);
fabeltranm 0:61199d9d0aed 94 deviceM.write_digit(1,4,0b10101010);
fabeltranm 0:61199d9d0aed 95 deviceM.write_digit(1,5,0b01010101);
fabeltranm 0:61199d9d0aed 96 deviceM.write_digit(1,6,0b10101010);
fabeltranm 0:61199d9d0aed 97 deviceM.write_digit(1,7,0b01010101);
fabeltranm 0:61199d9d0aed 98 }
fabeltranm 0:61199d9d0aed 99 }
fabeltranm 0:61199d9d0aed 100 */
fabeltranm 0:61199d9d0aed 101