Nasrun Hayeeyama
/
ColorMbed
Nasrun handsome
Revision 0:6e7a6e71dad3, committed 2016-12-03
- Comitter:
- dragondrunk
- Date:
- Sat Dec 03 10:17:37 2016 +0000
- Commit message:
- Nasrun
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ColorMbed.cpp Sat Dec 03 10:17:37 2016 +0000 @@ -0,0 +1,105 @@ +#include "mbed.h" +#include "ColorMbed.h" + +SPI dot_matrix(D11,NC,D13); //mosi miso sclk +DigitalOut lat(PA_12); +DigitalOut sb(PA_11); +DigitalOut rst(D10); +BusOut open_line(D2,D3,D4,D5,D6,D7,D8,D9); + //c0 c1 c2 c3 c4 c5 c6 c7 dont foget d7 +uint8_t temp; +uint8_t position[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; +int line[8] = {1,2,4,8,16,32,64,128}; + +void ColorMbed::init(){ + dot_matrix.frequency(1000000); + uint8_t wb[3] = {255,255,255}; + rst = 1; + wait(0.5); + rst = 0; + wait(0.5); + rst = 1; + wait(0.5); + sb = 0; // 6 bit + for(int i = 0; i<8; i++){ + dot_matrix.write(wb[0]); + dot_matrix.write(wb[1]); + dot_matrix.write(wb[2]); + } + open_line = 0; + sb = 1; // 8 bit +} + +// *********************** configur later ********************************* +void ColorMbed::display_dot(int row,int col ,uint8_t *color){ + //for(int j = 0; j<8;j++){ + temp = position[col]; + for(int i = 0 ; i< 8 ; i++){ + if(temp & 0x80){ + dot_matrix.write(color[0]); + dot_matrix.write(color[1]); + dot_matrix.write(color[2]); + } + else{ + dot_matrix.write(0); + dot_matrix.write(0); + dot_matrix.write(0); + } + temp = temp << 1; + } + lat = 1; + lat = 0; + open_line = line[row]; + wait(0.6); + open_line = 0; + wait(0.4); + //} +} + +// void ColorMbed::display_ship(int row,int column,int type,uint8_t *color){ +// if(type == 1){ +// +// } +// else if(type == 2){ +// +// } +// } + +void ColorMbed::display_pic(uint8_t *pic,uint8_t *color){ + for(int j = 0;j<8;j++){ + temp = pic[j]; + for(int i = 0; i<8; i++){ + if(temp & 0x80){ + dot_matrix.write(color[0]); + dot_matrix.write(color[1]); + dot_matrix.write(color[2]); + } + else{ + dot_matrix.write(0); + dot_matrix.write(0); + dot_matrix.write(0); + } + temp = temp << 1; + } + lat = 1; + lat = 0; + open_line = line[j]; + wait(0.001); + open_line = 0; + } +} + +// *********************** private function ********************************* + + +int ColorMbed::_power(int number , int power){ + int i = 0; + int number1 = number; + if(power == 0){return 1;} + for(i = 1 ; i <= power ; i++ ){ + if(power == 1){return number;} + if(i == 1){number = number * 1;} + else{number1 = number1 * number;} + } +return number1; +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ColorMbed.h Sat Dec 03 10:17:37 2016 +0000 @@ -0,0 +1,56 @@ +/* +************************************* +I have some idea to create only three function +display ship; +display dot or bomb; +finally display game interface; +************************************* +*/ + +#ifndef ColorMbed_H +#define ColorMbed_H + +#include "mbed.h" + +class ColorMbed{ + +public: + + void init(); // set white_balance + /* + display_dot can display one dot on dot matrix + parameter : + row : int (1,2,3,...,8) + column : int (1,2,3,...,8) + color : {B,G,R} + */ + void display_dot(int row,int column,uint8_t *color); + /* + display_ship 1 to 8 such as + ship 1 is 4 chanal on dot matrix + ship 2 is 3 chanal on dot matrix + 2 : ship 3 is 2 chanal on dot matrix + 4 : ship 4 is 1 chanal on dot matrix + fix rgb !!! + parameter : + type : int (ship 1..2.3.4) + row : int (1,2,3,4,...,8) + column : int (1,2,3,4,...,8) + */ + void display_ship(int row,int column,int type,uint8_t *color); + + void display_pic(uint8_t *pic,uint8_t *color); + /* + display picture from hexa code color in this function is + only color and blank + */ + + + +private : + + int _power(int number , int power); // power number +}; + + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Dec 03 10:17:37 2016 +0000 @@ -0,0 +1,27 @@ +/***************** For test only ****************/ + +#include "mbed.h" +#include "ColorMbed.h" + +ColorMbed dotmatrix; +Timer t; + +int main(){ + // uint8_t rgb[3] = {255,255,100}; + uint8_t rgb[3] = {10,20,0}; + uint8_t pic[8] = {0x1C,0x00,0x20,0x20,0x20,0x20,0x00,0x00}; + uint8_t pic2[8] = {0x01,0x02,0x04,0x08,0x10,0x20,0x40,0x80}; + uint8_t dream_ship[8] = {0x40,0x50,0x41,0x4E,0x00,0x92,0x14,0x04}; + // for coordinate + //uint8_t pic2[8] = {0x7E,0xDF,0xFF,0xF0,0xFF,0x7E,0x3C,0x3C}; + //uint8_t tmp_pic[8] = {0}; + dotmatrix.init(); + + while(1){ + dotmatrix.display_pic(dream_ship,rgb); + } + + return 0; + + +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Dec 03 10:17:37 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/25aea2a3f4e3 \ No newline at end of file