Nasrun Hayeeyama
/
project_ShipDot
Nasrun
Fork of project_ShipDot by
ColorMbed.cpp@22:5bc894988f11, 2016-12-04 (annotated)
- Committer:
- dragondrunk
- Date:
- Sun Dec 04 05:02:03 2016 +0000
- Revision:
- 22:5bc894988f11
add dotmatrix display (only place ship)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dragondrunk | 22:5bc894988f11 | 1 | #include "ColorMbed.h" |
dragondrunk | 22:5bc894988f11 | 2 | #include "mbed.h" |
dragondrunk | 22:5bc894988f11 | 3 | |
dragondrunk | 22:5bc894988f11 | 4 | SPI dot_matrix(D11,NC,D13); //mosi miso sclk |
dragondrunk | 22:5bc894988f11 | 5 | DigitalOut lat(PA_12); |
dragondrunk | 22:5bc894988f11 | 6 | DigitalOut sb(PA_11); |
dragondrunk | 22:5bc894988f11 | 7 | DigitalOut rst(D10); |
dragondrunk | 22:5bc894988f11 | 8 | BusOut open_line(D2,D3,D4,D5,D6,D7,D8,D9); |
dragondrunk | 22:5bc894988f11 | 9 | //c0 c1 c2 c3 c4 c5 c6 c7 dont foget d7 |
dragondrunk | 22:5bc894988f11 | 10 | int temp; |
dragondrunk | 22:5bc894988f11 | 11 | int line[8] = {1,2,4,8,16,32,64,128}; |
dragondrunk | 22:5bc894988f11 | 12 | |
dragondrunk | 22:5bc894988f11 | 13 | void ColorMbed::init(){ |
dragondrunk | 22:5bc894988f11 | 14 | dot_matrix.frequency(1000000); |
dragondrunk | 22:5bc894988f11 | 15 | uint8_t wb[3] = {255,255,255}; |
dragondrunk | 22:5bc894988f11 | 16 | rst = 1; |
dragondrunk | 22:5bc894988f11 | 17 | wait(0.5); |
dragondrunk | 22:5bc894988f11 | 18 | rst = 0; |
dragondrunk | 22:5bc894988f11 | 19 | wait(0.5); |
dragondrunk | 22:5bc894988f11 | 20 | rst = 1; |
dragondrunk | 22:5bc894988f11 | 21 | wait(0.5); |
dragondrunk | 22:5bc894988f11 | 22 | sb = 0; // 6 bit |
dragondrunk | 22:5bc894988f11 | 23 | for(int i = 0; i<8; i++){ |
dragondrunk | 22:5bc894988f11 | 24 | dot_matrix.write(wb[0]); |
dragondrunk | 22:5bc894988f11 | 25 | dot_matrix.write(wb[1]); |
dragondrunk | 22:5bc894988f11 | 26 | dot_matrix.write(wb[2]); |
dragondrunk | 22:5bc894988f11 | 27 | } |
dragondrunk | 22:5bc894988f11 | 28 | open_line = 0; |
dragondrunk | 22:5bc894988f11 | 29 | sb = 1; // 8 bit |
dragondrunk | 22:5bc894988f11 | 30 | } |
dragondrunk | 22:5bc894988f11 | 31 | |
dragondrunk | 22:5bc894988f11 | 32 | // *********************** configur later ********************************* |
dragondrunk | 22:5bc894988f11 | 33 | |
dragondrunk | 22:5bc894988f11 | 34 | // void ColorMbed::display_ship(int row,int column,int type,uint8_t *color){ |
dragondrunk | 22:5bc894988f11 | 35 | // if(type == 1){ |
dragondrunk | 22:5bc894988f11 | 36 | // |
dragondrunk | 22:5bc894988f11 | 37 | // } |
dragondrunk | 22:5bc894988f11 | 38 | // else if(type == 2){ |
dragondrunk | 22:5bc894988f11 | 39 | // |
dragondrunk | 22:5bc894988f11 | 40 | // } |
dragondrunk | 22:5bc894988f11 | 41 | // } |
dragondrunk | 22:5bc894988f11 | 42 | |
dragondrunk | 22:5bc894988f11 | 43 | void ColorMbed::display_pic(int *pic,int *color){ |
dragondrunk | 22:5bc894988f11 | 44 | for(int j = 0;j<8;j++){ |
dragondrunk | 22:5bc894988f11 | 45 | temp = pic[j]; |
dragondrunk | 22:5bc894988f11 | 46 | for(int i = 0; i<8; i++){ |
dragondrunk | 22:5bc894988f11 | 47 | if(temp & 0x80){ |
dragondrunk | 22:5bc894988f11 | 48 | dot_matrix.write(color[0]); |
dragondrunk | 22:5bc894988f11 | 49 | dot_matrix.write(color[1]); |
dragondrunk | 22:5bc894988f11 | 50 | dot_matrix.write(color[2]); |
dragondrunk | 22:5bc894988f11 | 51 | } |
dragondrunk | 22:5bc894988f11 | 52 | else{ |
dragondrunk | 22:5bc894988f11 | 53 | dot_matrix.write(0); |
dragondrunk | 22:5bc894988f11 | 54 | dot_matrix.write(0); |
dragondrunk | 22:5bc894988f11 | 55 | dot_matrix.write(0); |
dragondrunk | 22:5bc894988f11 | 56 | } |
dragondrunk | 22:5bc894988f11 | 57 | temp = temp << 1; |
dragondrunk | 22:5bc894988f11 | 58 | } |
dragondrunk | 22:5bc894988f11 | 59 | lat = 1; |
dragondrunk | 22:5bc894988f11 | 60 | lat = 0; |
dragondrunk | 22:5bc894988f11 | 61 | open_line = line[j]; |
dragondrunk | 22:5bc894988f11 | 62 | wait(0.001); |
dragondrunk | 22:5bc894988f11 | 63 | open_line = 0; |
dragondrunk | 22:5bc894988f11 | 64 | } |
dragondrunk | 22:5bc894988f11 | 65 | } |
dragondrunk | 22:5bc894988f11 | 66 | |
dragondrunk | 22:5bc894988f11 | 67 | // *********************** private function ********************************* |
dragondrunk | 22:5bc894988f11 | 68 | |
dragondrunk | 22:5bc894988f11 | 69 | |
dragondrunk | 22:5bc894988f11 | 70 | int ColorMbed::_power(int number , int power){ |
dragondrunk | 22:5bc894988f11 | 71 | int i = 0; |
dragondrunk | 22:5bc894988f11 | 72 | int number1 = number; |
dragondrunk | 22:5bc894988f11 | 73 | if(power == 0){return 1;} |
dragondrunk | 22:5bc894988f11 | 74 | for(i = 1 ; i <= power ; i++ ){ |
dragondrunk | 22:5bc894988f11 | 75 | if(power == 1){return number;} |
dragondrunk | 22:5bc894988f11 | 76 | if(i == 1){number = number * 1;} |
dragondrunk | 22:5bc894988f11 | 77 | else{number1 = number1 * number;} |
dragondrunk | 22:5bc894988f11 | 78 | } |
dragondrunk | 22:5bc894988f11 | 79 | return number1; |
dragondrunk | 22:5bc894988f11 | 80 | } |