scroll string on MARMEX-OB
Dependencies: MARMEX_OB_oled_J mbed
main.cpp@0:39b78248fd07, 2014-05-20 (annotated)
- Committer:
- Naoto_111
- Date:
- Tue May 20 15:39:36 2014 +0000
- Revision:
- 0:39b78248fd07
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Naoto_111 | 0:39b78248fd07 | 1 | #include "mbed.h" |
Naoto_111 | 0:39b78248fd07 | 2 | #include "MARMEX_OB_oled.h" |
Naoto_111 | 0:39b78248fd07 | 3 | #include "lcharmap.h" |
Naoto_111 | 0:39b78248fd07 | 4 | |
Naoto_111 | 0:39b78248fd07 | 5 | //"LCHAR_HEIGHT", "LCHAR_WIDTH" -> "lcharmap.h" |
Naoto_111 | 0:39b78248fd07 | 6 | DigitalOut myled(LED1); |
Naoto_111 | 0:39b78248fd07 | 7 | MARMEX_OB_oled oled1( p5, p7, p8, p30, p11 ); // mosi, sclk, cs, rst, power_control |
Naoto_111 | 0:39b78248fd07 | 8 | |
Naoto_111 | 0:39b78248fd07 | 9 | void strscroll(char *str, int len); |
Naoto_111 | 0:39b78248fd07 | 10 | void arraycopy(char array1[LCHAR_HEIGHT][LCHAR_WIDTH+MARGIN],char array2[LCHAR_HEIGHT][LCHAR_WIDTH+MARGIN]); |
Naoto_111 | 0:39b78248fd07 | 11 | void arraycopy2(char array1[][LCHAR_HEIGHT][LCHAR_WIDTH],char array2[LCHAR_HEIGHT][LCHAR_WIDTH+MARGIN], int n); |
Naoto_111 | 0:39b78248fd07 | 12 | |
Naoto_111 | 0:39b78248fd07 | 13 | int main() |
Naoto_111 | 0:39b78248fd07 | 14 | { |
Naoto_111 | 0:39b78248fd07 | 15 | oled1.background( 0x000000 ); |
Naoto_111 | 0:39b78248fd07 | 16 | oled1.cls(); |
Naoto_111 | 0:39b78248fd07 | 17 | char str[]={"ABC abc"};//input massage |
Naoto_111 | 0:39b78248fd07 | 18 | strscroll(str,strlen(str)); |
Naoto_111 | 0:39b78248fd07 | 19 | |
Naoto_111 | 0:39b78248fd07 | 20 | } |
Naoto_111 | 0:39b78248fd07 | 21 | |
Naoto_111 | 0:39b78248fd07 | 22 | void strscroll(char *str, int len) |
Naoto_111 | 0:39b78248fd07 | 23 | { |
Naoto_111 | 0:39b78248fd07 | 24 | char left[LCHAR_HEIGHT][LCHAR_WIDTH+MARGIN], |
Naoto_111 | 0:39b78248fd07 | 25 | center[LCHAR_HEIGHT][LCHAR_WIDTH+MARGIN], |
Naoto_111 | 0:39b78248fd07 | 26 | right[LCHAR_HEIGHT][LCHAR_WIDTH+MARGIN]; |
Naoto_111 | 0:39b78248fd07 | 27 | arraycopy2(map_mark,left,0); |
Naoto_111 | 0:39b78248fd07 | 28 | arraycopy2(map_mark,center,0); |
Naoto_111 | 0:39b78248fd07 | 29 | |
Naoto_111 | 0:39b78248fd07 | 30 | for(int i=0; i<len+2; i++) { |
Naoto_111 | 0:39b78248fd07 | 31 | if(i>=len)arraycopy2(map_mark,right,0); |
Naoto_111 | 0:39b78248fd07 | 32 | else if('A'<=str[i]&&str[i]<='Z')arraycopy2(map_large,right,str[i]-'A'); |
Naoto_111 | 0:39b78248fd07 | 33 | else if('a'<=str[i]&&str[i]<='z')arraycopy2(map_small,right,str[i]-'a'); |
Naoto_111 | 0:39b78248fd07 | 34 | else if('0'<=str[i]&&str[i]<='9')arraycopy2(map_number,right,str[i]-'0'); |
Naoto_111 | 0:39b78248fd07 | 35 | else if(str[i]==32)arraycopy2(map_mark,right,0); |
Naoto_111 | 0:39b78248fd07 | 36 | else if(str[i]==',')arraycopy2(map_mark,right,1); |
Naoto_111 | 0:39b78248fd07 | 37 | else if(str[i]=='.')arraycopy2(map_mark,right,2); |
Naoto_111 | 0:39b78248fd07 | 38 | else oled1.cls(),myled=1,strscroll("ERROR", strlen("ERROR")),exit(EXIT_FAILURE); |
Naoto_111 | 0:39b78248fd07 | 39 | |
Naoto_111 | 0:39b78248fd07 | 40 | for(int x=15; x>=15-(LCHAR_WIDTH+MARGIN); x--) { |
Naoto_111 | 0:39b78248fd07 | 41 | for(int k=0; k<(LCHAR_WIDTH+MARGIN); k++) { |
Naoto_111 | 0:39b78248fd07 | 42 | for(int y=0; y<LCHAR_HEIGHT; y++) { |
Naoto_111 | 0:39b78248fd07 | 43 | int color; |
Naoto_111 | 0:39b78248fd07 | 44 | |
Naoto_111 | 0:39b78248fd07 | 45 | //left |
Naoto_111 | 0:39b78248fd07 | 46 | if(left[y][k]==1)color=0xFFFFFF; |
Naoto_111 | 0:39b78248fd07 | 47 | else color=0x000000; |
Naoto_111 | 0:39b78248fd07 | 48 | if(0<=x+k-(LCHAR_WIDTH+MARGIN)*2&&x+k-(LCHAR_WIDTH+MARGIN)*2<=15)oled1.fill((x+k-(LCHAR_WIDTH+MARGIN)*2)*8,y*8,8,8,color); |
Naoto_111 | 0:39b78248fd07 | 49 | |
Naoto_111 | 0:39b78248fd07 | 50 | //center |
Naoto_111 | 0:39b78248fd07 | 51 | if(center[y][k]==1)color=0xFFFFFF; |
Naoto_111 | 0:39b78248fd07 | 52 | else color=0x000000; |
Naoto_111 | 0:39b78248fd07 | 53 | if(0<=x+k-(LCHAR_WIDTH+MARGIN)&&x+k-(LCHAR_WIDTH+MARGIN)<=15)oled1.fill((x+k-(LCHAR_WIDTH+MARGIN))*8,y*8,8,8,color); |
Naoto_111 | 0:39b78248fd07 | 54 | |
Naoto_111 | 0:39b78248fd07 | 55 | //right |
Naoto_111 | 0:39b78248fd07 | 56 | if(right[y][k]==1)color=0xFFFFFF; |
Naoto_111 | 0:39b78248fd07 | 57 | else color=0x000000; |
Naoto_111 | 0:39b78248fd07 | 58 | if(0<=x+k&&x+k<=15)oled1.fill((x+k)*8,y*8,8,8,color); |
Naoto_111 | 0:39b78248fd07 | 59 | } |
Naoto_111 | 0:39b78248fd07 | 60 | |
Naoto_111 | 0:39b78248fd07 | 61 | } |
Naoto_111 | 0:39b78248fd07 | 62 | if(x!=15-(LCHAR_WIDTH+MARGIN))wait(0.1); |
Naoto_111 | 0:39b78248fd07 | 63 | } |
Naoto_111 | 0:39b78248fd07 | 64 | arraycopy(center,left); |
Naoto_111 | 0:39b78248fd07 | 65 | arraycopy(right,center); |
Naoto_111 | 0:39b78248fd07 | 66 | } |
Naoto_111 | 0:39b78248fd07 | 67 | |
Naoto_111 | 0:39b78248fd07 | 68 | |
Naoto_111 | 0:39b78248fd07 | 69 | } |
Naoto_111 | 0:39b78248fd07 | 70 | |
Naoto_111 | 0:39b78248fd07 | 71 | void arraycopy(char array1[LCHAR_HEIGHT][LCHAR_WIDTH+MARGIN],char array2[LCHAR_HEIGHT][LCHAR_WIDTH+MARGIN]){ |
Naoto_111 | 0:39b78248fd07 | 72 | for(int i=0; i<LCHAR_HEIGHT; i++)for(int j=0; j<LCHAR_WIDTH; j++)array2[i][j]=array1[i][j]; |
Naoto_111 | 0:39b78248fd07 | 73 | } |
Naoto_111 | 0:39b78248fd07 | 74 | |
Naoto_111 | 0:39b78248fd07 | 75 | void arraycopy2(char array1[][LCHAR_HEIGHT][LCHAR_WIDTH],char array2[LCHAR_HEIGHT][LCHAR_WIDTH+MARGIN], int n){ |
Naoto_111 | 0:39b78248fd07 | 76 | for(int i=0; i<LCHAR_HEIGHT; i++)for(int j=0; j<LCHAR_WIDTH+MARGIN; j++){ |
Naoto_111 | 0:39b78248fd07 | 77 | if(j>=LCHAR_WIDTH)array2[i][j]=0; |
Naoto_111 | 0:39b78248fd07 | 78 | else array2[i][j]=array1[n][i][j]; |
Naoto_111 | 0:39b78248fd07 | 79 | } |
Naoto_111 | 0:39b78248fd07 | 80 | } |