sota
Dependencies: mbed
Fork of newdot by
ColorMbed.cpp@3:d8133244484f, 2017-12-12 (annotated)
- Committer:
- sotter
- Date:
- Tue Dec 12 21:07:36 2017 +0000
- Revision:
- 3:d8133244484f
- Parent:
- 2:d714fd7bb7d5
hhhhh
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dragondrunk | 0:6e7a6e71dad3 | 1 | #include "mbed.h" |
dragondrunk | 0:6e7a6e71dad3 | 2 | #include "ColorMbed.h" |
dragondrunk | 0:6e7a6e71dad3 | 3 | |
sotter | 1:be91a16b48ea | 4 | SPI dot_matrix(PB_15,NC,PB_13); //mosi miso sclk |
sotter | 1:be91a16b48ea | 5 | DigitalOut lat(PA_13); |
sotter | 1:be91a16b48ea | 6 | DigitalOut sb(PA_14); |
dragondrunk | 0:6e7a6e71dad3 | 7 | DigitalOut rst(D10); |
sotter | 1:be91a16b48ea | 8 | BusOut open_line(PC_4,PB_14,PB_1,PB_2,PB_12,PC_5,PC_6,PC_8); |
dragondrunk | 0:6e7a6e71dad3 | 9 | //c0 c1 c2 c3 c4 c5 c6 c7 dont foget d7 |
dragondrunk | 0:6e7a6e71dad3 | 10 | uint8_t temp; |
dragondrunk | 0:6e7a6e71dad3 | 11 | uint8_t position[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; |
dragondrunk | 0:6e7a6e71dad3 | 12 | int line[8] = {1,2,4,8,16,32,64,128}; |
dragondrunk | 0:6e7a6e71dad3 | 13 | |
dragondrunk | 0:6e7a6e71dad3 | 14 | void ColorMbed::init(){ |
sotter | 1:be91a16b48ea | 15 | dot_matrix.frequency(2000000000); |
dragondrunk | 0:6e7a6e71dad3 | 16 | uint8_t wb[3] = {255,255,255}; |
dragondrunk | 0:6e7a6e71dad3 | 17 | rst = 1; |
dragondrunk | 0:6e7a6e71dad3 | 18 | wait(0.5); |
dragondrunk | 0:6e7a6e71dad3 | 19 | rst = 0; |
dragondrunk | 0:6e7a6e71dad3 | 20 | wait(0.5); |
dragondrunk | 0:6e7a6e71dad3 | 21 | rst = 1; |
dragondrunk | 0:6e7a6e71dad3 | 22 | wait(0.5); |
dragondrunk | 0:6e7a6e71dad3 | 23 | sb = 0; // 6 bit |
dragondrunk | 0:6e7a6e71dad3 | 24 | for(int i = 0; i<8; i++){ |
dragondrunk | 0:6e7a6e71dad3 | 25 | dot_matrix.write(wb[0]); |
dragondrunk | 0:6e7a6e71dad3 | 26 | dot_matrix.write(wb[1]); |
dragondrunk | 0:6e7a6e71dad3 | 27 | dot_matrix.write(wb[2]); |
dragondrunk | 0:6e7a6e71dad3 | 28 | } |
dragondrunk | 0:6e7a6e71dad3 | 29 | open_line = 0; |
dragondrunk | 0:6e7a6e71dad3 | 30 | sb = 1; // 8 bit |
dragondrunk | 0:6e7a6e71dad3 | 31 | } |
dragondrunk | 0:6e7a6e71dad3 | 32 | |
dragondrunk | 0:6e7a6e71dad3 | 33 | // *********************** configur later ********************************* |
dragondrunk | 0:6e7a6e71dad3 | 34 | void ColorMbed::display_dot(int row,int col ,uint8_t *color){ |
dragondrunk | 0:6e7a6e71dad3 | 35 | //for(int j = 0; j<8;j++){ |
dragondrunk | 0:6e7a6e71dad3 | 36 | temp = position[col]; |
dragondrunk | 0:6e7a6e71dad3 | 37 | for(int i = 0 ; i< 8 ; i++){ |
dragondrunk | 0:6e7a6e71dad3 | 38 | if(temp & 0x80){ |
dragondrunk | 0:6e7a6e71dad3 | 39 | dot_matrix.write(color[0]); |
dragondrunk | 0:6e7a6e71dad3 | 40 | dot_matrix.write(color[1]); |
dragondrunk | 0:6e7a6e71dad3 | 41 | dot_matrix.write(color[2]); |
dragondrunk | 0:6e7a6e71dad3 | 42 | } |
dragondrunk | 0:6e7a6e71dad3 | 43 | else{ |
dragondrunk | 0:6e7a6e71dad3 | 44 | dot_matrix.write(0); |
dragondrunk | 0:6e7a6e71dad3 | 45 | dot_matrix.write(0); |
dragondrunk | 0:6e7a6e71dad3 | 46 | dot_matrix.write(0); |
dragondrunk | 0:6e7a6e71dad3 | 47 | } |
dragondrunk | 0:6e7a6e71dad3 | 48 | temp = temp << 1; |
dragondrunk | 0:6e7a6e71dad3 | 49 | } |
dragondrunk | 0:6e7a6e71dad3 | 50 | lat = 1; |
dragondrunk | 0:6e7a6e71dad3 | 51 | lat = 0; |
dragondrunk | 0:6e7a6e71dad3 | 52 | open_line = line[row]; |
dragondrunk | 0:6e7a6e71dad3 | 53 | wait(0.6); |
dragondrunk | 0:6e7a6e71dad3 | 54 | open_line = 0; |
dragondrunk | 0:6e7a6e71dad3 | 55 | wait(0.4); |
dragondrunk | 0:6e7a6e71dad3 | 56 | //} |
dragondrunk | 0:6e7a6e71dad3 | 57 | } |
dragondrunk | 0:6e7a6e71dad3 | 58 | |
dragondrunk | 0:6e7a6e71dad3 | 59 | // void ColorMbed::display_ship(int row,int column,int type,uint8_t *color){ |
dragondrunk | 0:6e7a6e71dad3 | 60 | // if(type == 1){ |
dragondrunk | 0:6e7a6e71dad3 | 61 | // |
dragondrunk | 0:6e7a6e71dad3 | 62 | // } |
dragondrunk | 0:6e7a6e71dad3 | 63 | // else if(type == 2){ |
dragondrunk | 0:6e7a6e71dad3 | 64 | // |
dragondrunk | 0:6e7a6e71dad3 | 65 | // } |
dragondrunk | 0:6e7a6e71dad3 | 66 | // } |
dragondrunk | 0:6e7a6e71dad3 | 67 | |
dragondrunk | 0:6e7a6e71dad3 | 68 | void ColorMbed::display_pic(uint8_t *pic,uint8_t *color){ |
dragondrunk | 0:6e7a6e71dad3 | 69 | for(int j = 0;j<8;j++){ |
dragondrunk | 0:6e7a6e71dad3 | 70 | temp = pic[j]; |
dragondrunk | 0:6e7a6e71dad3 | 71 | for(int i = 0; i<8; i++){ |
dragondrunk | 0:6e7a6e71dad3 | 72 | if(temp & 0x80){ |
dragondrunk | 0:6e7a6e71dad3 | 73 | dot_matrix.write(color[0]); |
dragondrunk | 0:6e7a6e71dad3 | 74 | dot_matrix.write(color[1]); |
dragondrunk | 0:6e7a6e71dad3 | 75 | dot_matrix.write(color[2]); |
dragondrunk | 0:6e7a6e71dad3 | 76 | } |
dragondrunk | 0:6e7a6e71dad3 | 77 | else{ |
dragondrunk | 0:6e7a6e71dad3 | 78 | dot_matrix.write(0); |
dragondrunk | 0:6e7a6e71dad3 | 79 | dot_matrix.write(0); |
dragondrunk | 0:6e7a6e71dad3 | 80 | dot_matrix.write(0); |
dragondrunk | 0:6e7a6e71dad3 | 81 | } |
dragondrunk | 0:6e7a6e71dad3 | 82 | temp = temp << 1; |
dragondrunk | 0:6e7a6e71dad3 | 83 | } |
dragondrunk | 0:6e7a6e71dad3 | 84 | lat = 1; |
dragondrunk | 0:6e7a6e71dad3 | 85 | lat = 0; |
dragondrunk | 0:6e7a6e71dad3 | 86 | open_line = line[j]; |
sotter | 2:d714fd7bb7d5 | 87 | wait(0.00005); |
dragondrunk | 0:6e7a6e71dad3 | 88 | open_line = 0; |
dragondrunk | 0:6e7a6e71dad3 | 89 | } |
dragondrunk | 0:6e7a6e71dad3 | 90 | } |
dragondrunk | 0:6e7a6e71dad3 | 91 | |
dragondrunk | 0:6e7a6e71dad3 | 92 | // *********************** private function ********************************* |
dragondrunk | 0:6e7a6e71dad3 | 93 | |
dragondrunk | 0:6e7a6e71dad3 | 94 | |
dragondrunk | 0:6e7a6e71dad3 | 95 | int ColorMbed::_power(int number , int power){ |
dragondrunk | 0:6e7a6e71dad3 | 96 | int i = 0; |
dragondrunk | 0:6e7a6e71dad3 | 97 | int number1 = number; |
dragondrunk | 0:6e7a6e71dad3 | 98 | if(power == 0){return 1;} |
dragondrunk | 0:6e7a6e71dad3 | 99 | for(i = 1 ; i <= power ; i++ ){ |
dragondrunk | 0:6e7a6e71dad3 | 100 | if(power == 1){return number;} |
dragondrunk | 0:6e7a6e71dad3 | 101 | if(i == 1){number = number * 1;} |
dragondrunk | 0:6e7a6e71dad3 | 102 | else{number1 = number1 * number;} |
dragondrunk | 0:6e7a6e71dad3 | 103 | } |
dragondrunk | 0:6e7a6e71dad3 | 104 | return number1; |
dragondrunk | 0:6e7a6e71dad3 | 105 | } |