B13 final project part 1
Dependencies: mbed
main.cpp@0:0def0023f900, 2015-12-08 (annotated)
- Committer:
- mbedobsza
- Date:
- Tue Dec 08 21:42:56 2015 +0000
- Revision:
- 0:0def0023f900
13B_slave-fra221-6476
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbedobsza | 0:0def0023f900 | 1 | #include "mbed.h" |
mbedobsza | 0:0def0023f900 | 2 | #include "iteadstudio_colourshield.h" |
mbedobsza | 0:0def0023f900 | 3 | uint8_t frame[8][8][3]= {0}; |
mbedobsza | 0:0def0023f900 | 4 | char mode = '1'; |
mbedobsza | 0:0def0023f900 | 5 | char read = '0'; |
mbedobsza | 0:0def0023f900 | 6 | char readon,readi,readj; |
mbedobsza | 0:0def0023f900 | 7 | char trig = '0'; |
mbedobsza | 0:0def0023f900 | 8 | char trigkey; |
mbedobsza | 0:0def0023f900 | 9 | uint8_t keyarray[4][4] = {{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}}; |
mbedobsza | 0:0def0023f900 | 10 | DigitalIn usrin(PC_13); |
mbedobsza | 0:0def0023f900 | 11 | inline void midicon_display(uint8_t array[4][4],uint8_t BGR_col_map[4][4][3]); |
mbedobsza | 0:0def0023f900 | 12 | inline void midi_rythm_display(uint8_t BGR_col_map88[8][8][3]); |
mbedobsza | 0:0def0023f900 | 13 | Serial master(PA_11,PA_12); |
mbedobsza | 0:0def0023f900 | 14 | Serial pc(USBTX, USBRX); |
mbedobsza | 0:0def0023f900 | 15 | Timer timer; |
mbedobsza | 0:0def0023f900 | 16 | Timer timer2; |
mbedobsza | 0:0def0023f900 | 17 | int scount; |
mbedobsza | 0:0def0023f900 | 18 | |
mbedobsza | 0:0def0023f900 | 19 | |
mbedobsza | 0:0def0023f900 | 20 | int begin; |
mbedobsza | 0:0def0023f900 | 21 | void callback() |
mbedobsza | 0:0def0023f900 | 22 | { |
mbedobsza | 0:0def0023f900 | 23 | // Note: you need to actually read from the serial to clear the RX interrupt |
mbedobsza | 0:0def0023f900 | 24 | if(pc.getc()=='#') { |
mbedobsza | 0:0def0023f900 | 25 | mode = pc.getc(); |
mbedobsza | 0:0def0023f900 | 26 | pc.putc(mode); |
mbedobsza | 0:0def0023f900 | 27 | } |
mbedobsza | 0:0def0023f900 | 28 | } |
mbedobsza | 0:0def0023f900 | 29 | void callbackmaster() |
mbedobsza | 0:0def0023f900 | 30 | { |
mbedobsza | 0:0def0023f900 | 31 | // Note: you need to actually read from the serial to clear the RX interrupt |
mbedobsza | 0:0def0023f900 | 32 | read =master.getc(); |
mbedobsza | 0:0def0023f900 | 33 | if(read=='#') { |
mbedobsza | 0:0def0023f900 | 34 | mode = master.getc(); |
mbedobsza | 0:0def0023f900 | 35 | pc.putc(mode); |
mbedobsza | 0:0def0023f900 | 36 | } else if(read == '$') { |
mbedobsza | 0:0def0023f900 | 37 | //pc.putc(read); |
mbedobsza | 0:0def0023f900 | 38 | readon = master.getc(); |
mbedobsza | 0:0def0023f900 | 39 | //pc.putc(readon); |
mbedobsza | 0:0def0023f900 | 40 | readi=master.getc(); |
mbedobsza | 0:0def0023f900 | 41 | //pc.putc(readi); |
mbedobsza | 0:0def0023f900 | 42 | readj=master.getc(); |
mbedobsza | 0:0def0023f900 | 43 | //pc.putc(readj); |
mbedobsza | 0:0def0023f900 | 44 | //pc.putc('\n'); |
mbedobsza | 0:0def0023f900 | 45 | if(readon=='1') { |
mbedobsza | 0:0def0023f900 | 46 | keyarray[3-(readj-'0')][(readi-'0')] =1; |
mbedobsza | 0:0def0023f900 | 47 | } |
mbedobsza | 0:0def0023f900 | 48 | if(readon=='0') { |
mbedobsza | 0:0def0023f900 | 49 | //pc.putc('X'); |
mbedobsza | 0:0def0023f900 | 50 | keyarray[3-(readj-'0')][readi-'0'] = 0; |
mbedobsza | 0:0def0023f900 | 51 | } |
mbedobsza | 0:0def0023f900 | 52 | } else if(read == '*') { |
mbedobsza | 0:0def0023f900 | 53 | trig ='1'; |
mbedobsza | 0:0def0023f900 | 54 | pc.putc('!'); |
mbedobsza | 0:0def0023f900 | 55 | trigkey = master.getc(); |
mbedobsza | 0:0def0023f900 | 56 | pc.putc(trigkey); |
mbedobsza | 0:0def0023f900 | 57 | pc.putc('\n'); |
mbedobsza | 0:0def0023f900 | 58 | } else { |
mbedobsza | 0:0def0023f900 | 59 | pc.putc('-'); |
mbedobsza | 0:0def0023f900 | 60 | pc.putc(read); |
mbedobsza | 0:0def0023f900 | 61 | pc.putc('-'); |
mbedobsza | 0:0def0023f900 | 62 | pc.putc('\n'); |
mbedobsza | 0:0def0023f900 | 63 | } |
mbedobsza | 0:0def0023f900 | 64 | } |
mbedobsza | 0:0def0023f900 | 65 | int main() |
mbedobsza | 0:0def0023f900 | 66 | { |
mbedobsza | 0:0def0023f900 | 67 | timer.start(); |
mbedobsza | 0:0def0023f900 | 68 | pc.baud(115200); |
mbedobsza | 0:0def0023f900 | 69 | pc.attach(&callback); |
mbedobsza | 0:0def0023f900 | 70 | master.baud(115200); |
mbedobsza | 0:0def0023f900 | 71 | master.attach(&callbackmaster); |
mbedobsza | 0:0def0023f900 | 72 | |
mbedobsza | 0:0def0023f900 | 73 | char wb[3]= {100,100,100}; |
mbedobsza | 0:0def0023f900 | 74 | INITRGB(wb); |
mbedobsza | 0:0def0023f900 | 75 | float r,g,b; |
mbedobsza | 0:0def0023f900 | 76 | //float HSV[3]; |
mbedobsza | 0:0def0023f900 | 77 | |
mbedobsza | 0:0def0023f900 | 78 | while(1) { |
mbedobsza | 0:0def0023f900 | 79 | if(mode=='0') { |
mbedobsza | 0:0def0023f900 | 80 | for(int i =0; i<8; i++) { |
mbedobsza | 0:0def0023f900 | 81 | for(int j= 0; j<8; j++) { |
mbedobsza | 0:0def0023f900 | 82 | HSVtoRGB(&r,&g,&b,i*j*360/49,1,1); |
mbedobsza | 0:0def0023f900 | 83 | frame[i][j][0]=(uint8_t)(b*230); |
mbedobsza | 0:0def0023f900 | 84 | frame[i][j][1]=(uint8_t)(g*255); |
mbedobsza | 0:0def0023f900 | 85 | frame[i][j][2]=(uint8_t)(r*155); |
mbedobsza | 0:0def0023f900 | 86 | |
mbedobsza | 0:0def0023f900 | 87 | } |
mbedobsza | 0:0def0023f900 | 88 | } |
mbedobsza | 0:0def0023f900 | 89 | while(mode == '0') { |
mbedobsza | 0:0def0023f900 | 90 | sendframe(frame); |
mbedobsza | 0:0def0023f900 | 91 | displayRGB(); |
mbedobsza | 0:0def0023f900 | 92 | |
mbedobsza | 0:0def0023f900 | 93 | |
mbedobsza | 0:0def0023f900 | 94 | } |
mbedobsza | 0:0def0023f900 | 95 | } |
mbedobsza | 0:0def0023f900 | 96 | if(mode=='1') { |
mbedobsza | 0:0def0023f900 | 97 | //rainbow keymap |
mbedobsza | 0:0def0023f900 | 98 | |
mbedobsza | 0:0def0023f900 | 99 | uint8_t bgr_col_map[4][4][3]; |
mbedobsza | 0:0def0023f900 | 100 | |
mbedobsza | 0:0def0023f900 | 101 | int key = 0; |
mbedobsza | 0:0def0023f900 | 102 | for(int i=0 ; i<4; i++) { |
mbedobsza | 0:0def0023f900 | 103 | for(int j=0 ; j<4; j++) { |
mbedobsza | 0:0def0023f900 | 104 | HSVtoRGB(&r,&g,&b,key*360/15,1,1); |
mbedobsza | 0:0def0023f900 | 105 | bgr_col_map[j][i][0] = (uint8_t)(b*230); |
mbedobsza | 0:0def0023f900 | 106 | bgr_col_map[j][i][1] = (uint8_t)(g*255); |
mbedobsza | 0:0def0023f900 | 107 | bgr_col_map[j][i][2] = (uint8_t)(r*155); |
mbedobsza | 0:0def0023f900 | 108 | key++; |
mbedobsza | 0:0def0023f900 | 109 | } |
mbedobsza | 0:0def0023f900 | 110 | } |
mbedobsza | 0:0def0023f900 | 111 | |
mbedobsza | 0:0def0023f900 | 112 | while(mode == '1') { |
mbedobsza | 0:0def0023f900 | 113 | midicon_display(keyarray,bgr_col_map); |
mbedobsza | 0:0def0023f900 | 114 | } |
mbedobsza | 0:0def0023f900 | 115 | |
mbedobsza | 0:0def0023f900 | 116 | } else if(mode=='2') { |
mbedobsza | 0:0def0023f900 | 117 | uint8_t rythm_col_map[8][8][3]; |
mbedobsza | 0:0def0023f900 | 118 | //first col |
mbedobsza | 0:0def0023f900 | 119 | for(int i = 0; i<2; i++) { |
mbedobsza | 0:0def0023f900 | 120 | for(int j =0; j<6; j++) { |
mbedobsza | 0:0def0023f900 | 121 | HSVtoRGB(&r,&g,&b,0,0,1); |
mbedobsza | 0:0def0023f900 | 122 | rythm_col_map[i][j][0]=(uint8_t)(b*230); |
mbedobsza | 0:0def0023f900 | 123 | rythm_col_map[i][j][1]=(uint8_t)(g*255); |
mbedobsza | 0:0def0023f900 | 124 | rythm_col_map[i][j][2]=(uint8_t)(r*155); |
mbedobsza | 0:0def0023f900 | 125 | } |
mbedobsza | 0:0def0023f900 | 126 | } |
mbedobsza | 0:0def0023f900 | 127 | //second col |
mbedobsza | 0:0def0023f900 | 128 | for(int i = 2; i<4; i++) { |
mbedobsza | 0:0def0023f900 | 129 | for(int j =0; j<6; j++) { |
mbedobsza | 0:0def0023f900 | 130 | HSVtoRGB(&r,&g,&b,0,0,1); |
mbedobsza | 0:0def0023f900 | 131 | rythm_col_map[i][j][0]=(uint8_t)(b*230); |
mbedobsza | 0:0def0023f900 | 132 | rythm_col_map[i][j][1]=(uint8_t)(g*255); |
mbedobsza | 0:0def0023f900 | 133 | rythm_col_map[i][j][2]=(uint8_t)(r*155); |
mbedobsza | 0:0def0023f900 | 134 | } |
mbedobsza | 0:0def0023f900 | 135 | } |
mbedobsza | 0:0def0023f900 | 136 | //third col |
mbedobsza | 0:0def0023f900 | 137 | for(int i = 4; i<6; i++) { |
mbedobsza | 0:0def0023f900 | 138 | for(int j =0; j<6; j++) { |
mbedobsza | 0:0def0023f900 | 139 | HSVtoRGB(&r,&g,&b,0,0,1); |
mbedobsza | 0:0def0023f900 | 140 | rythm_col_map[i][j][0]=(uint8_t)(b*230); |
mbedobsza | 0:0def0023f900 | 141 | rythm_col_map[i][j][1]=(uint8_t)(g*255); |
mbedobsza | 0:0def0023f900 | 142 | rythm_col_map[i][j][2]=(uint8_t)(r*155); |
mbedobsza | 0:0def0023f900 | 143 | } |
mbedobsza | 0:0def0023f900 | 144 | } |
mbedobsza | 0:0def0023f900 | 145 | //last col |
mbedobsza | 0:0def0023f900 | 146 | for(int i = 6; i<8; i++) { |
mbedobsza | 0:0def0023f900 | 147 | for(int j =0; j<6; j++) { |
mbedobsza | 0:0def0023f900 | 148 | HSVtoRGB(&r,&g,&b,0,0,1); |
mbedobsza | 0:0def0023f900 | 149 | rythm_col_map[i][j][0]=(uint8_t)(b*230); |
mbedobsza | 0:0def0023f900 | 150 | rythm_col_map[i][j][1]=(uint8_t)(g*255); |
mbedobsza | 0:0def0023f900 | 151 | rythm_col_map[i][j][2]=(uint8_t)(r*155); |
mbedobsza | 0:0def0023f900 | 152 | } |
mbedobsza | 0:0def0023f900 | 153 | } |
mbedobsza | 0:0def0023f900 | 154 | //allbutton |
mbedobsza | 0:0def0023f900 | 155 | for(int i = 0; i<8; i++) { |
mbedobsza | 0:0def0023f900 | 156 | for(int j =6; j<8; j++) { |
mbedobsza | 0:0def0023f900 | 157 | HSVtoRGB(&r,&g,&b,0,0,1); |
mbedobsza | 0:0def0023f900 | 158 | rythm_col_map[i][j][0]=(uint8_t)(b*230); |
mbedobsza | 0:0def0023f900 | 159 | rythm_col_map[i][j][1]=(uint8_t)(g*255); |
mbedobsza | 0:0def0023f900 | 160 | rythm_col_map[i][j][2]=(uint8_t)(r*155); |
mbedobsza | 0:0def0023f900 | 161 | } |
mbedobsza | 0:0def0023f900 | 162 | } |
mbedobsza | 0:0def0023f900 | 163 | |
mbedobsza | 0:0def0023f900 | 164 | uint8_t canvas[8][8][3]; |
mbedobsza | 0:0def0023f900 | 165 | //int velocity_ms = 100; |
mbedobsza | 0:0def0023f900 | 166 | uint8_t padobject[4][6][2] = {0}; //col,maxnumber of obj,avalibility,pos |
mbedobsza | 0:0def0023f900 | 167 | int i2; |
mbedobsza | 0:0def0023f900 | 168 | memcpy(canvas,rythm_col_map,sizeof(canvas)); |
mbedobsza | 0:0def0023f900 | 169 | while(mode == '2') { |
mbedobsza | 0:0def0023f900 | 170 | |
mbedobsza | 0:0def0023f900 | 171 | |
mbedobsza | 0:0def0023f900 | 172 | |
mbedobsza | 0:0def0023f900 | 173 | |
mbedobsza | 0:0def0023f900 | 174 | if(trig=='1') { |
mbedobsza | 0:0def0023f900 | 175 | memcpy(canvas,rythm_col_map,sizeof(canvas)); |
mbedobsza | 0:0def0023f900 | 176 | trig='0'; |
mbedobsza | 0:0def0023f900 | 177 | for(int i = 0 ; i<6; i++) { |
mbedobsza | 0:0def0023f900 | 178 | if(trigkey-'0'!=0) |
mbedobsza | 0:0def0023f900 | 179 | if(padobject[trigkey-'0'-1][i][0]==0) { |
mbedobsza | 0:0def0023f900 | 180 | padobject[trigkey-'0'-1][i][0]=1; |
mbedobsza | 0:0def0023f900 | 181 | break; |
mbedobsza | 0:0def0023f900 | 182 | } |
mbedobsza | 0:0def0023f900 | 183 | } |
mbedobsza | 0:0def0023f900 | 184 | for(int i =0; i<4; i++) { |
mbedobsza | 0:0def0023f900 | 185 | for(int j= 0; j<6; j++) { |
mbedobsza | 0:0def0023f900 | 186 | if(padobject[i][j][0]==1) { |
mbedobsza | 0:0def0023f900 | 187 | if(padobject[i][j][1]>5) { |
mbedobsza | 0:0def0023f900 | 188 | padobject[i][j][0] = 0; |
mbedobsza | 0:0def0023f900 | 189 | padobject[i][j][1] = 0; |
mbedobsza | 0:0def0023f900 | 190 | } else { |
mbedobsza | 0:0def0023f900 | 191 | //pc.putc('#'); |
mbedobsza | 0:0def0023f900 | 192 | i2 = i*2; |
mbedobsza | 0:0def0023f900 | 193 | canvas[i2][padobject[i][j][1]][0]=(uint8_t)(230); |
mbedobsza | 0:0def0023f900 | 194 | canvas[i2][padobject[i][j][1]][1]=(uint8_t)(204); |
mbedobsza | 0:0def0023f900 | 195 | canvas[i2][padobject[i][j][1]][2]=(uint8_t)(0); |
mbedobsza | 0:0def0023f900 | 196 | canvas[i2+1][padobject[i][j][1]][0]=(uint8_t)(230); |
mbedobsza | 0:0def0023f900 | 197 | canvas[i2+1][padobject[i][j][1]][1]=(uint8_t)(204); |
mbedobsza | 0:0def0023f900 | 198 | canvas[i2+1][padobject[i][j][1]][2]=(uint8_t)(0); |
mbedobsza | 0:0def0023f900 | 199 | padobject[i][j][1]++; |
mbedobsza | 0:0def0023f900 | 200 | } |
mbedobsza | 0:0def0023f900 | 201 | } |
mbedobsza | 0:0def0023f900 | 202 | } |
mbedobsza | 0:0def0023f900 | 203 | } |
mbedobsza | 0:0def0023f900 | 204 | } |
mbedobsza | 0:0def0023f900 | 205 | sendframe(canvas); |
mbedobsza | 0:0def0023f900 | 206 | displayRGB(); |
mbedobsza | 0:0def0023f900 | 207 | } |
mbedobsza | 0:0def0023f900 | 208 | } |
mbedobsza | 0:0def0023f900 | 209 | } |
mbedobsza | 0:0def0023f900 | 210 | } |
mbedobsza | 0:0def0023f900 | 211 | inline void midicon_display(uint8_t array[4][4],uint8_t BGR_col_map44[4][4][3]) |
mbedobsza | 0:0def0023f900 | 212 | { |
mbedobsza | 0:0def0023f900 | 213 | uint8_t frameX[8][8][3]= {0}; |
mbedobsza | 0:0def0023f900 | 214 | //memset(frameX,30,sizeof(frameX)); |
mbedobsza | 0:0def0023f900 | 215 | //memcpy(frameX,BGR_bac_map88,sizeof(frameX)); |
mbedobsza | 0:0def0023f900 | 216 | int n_x,n_y; |
mbedobsza | 0:0def0023f900 | 217 | for( int x=0; x<4; x++) { |
mbedobsza | 0:0def0023f900 | 218 | for( int y=0; y<4; y++) { |
mbedobsza | 0:0def0023f900 | 219 | if(array[x][y]==1) { |
mbedobsza | 0:0def0023f900 | 220 | |
mbedobsza | 0:0def0023f900 | 221 | |
mbedobsza | 0:0def0023f900 | 222 | n_x = x*2; |
mbedobsza | 0:0def0023f900 | 223 | n_y = y*2; |
mbedobsza | 0:0def0023f900 | 224 | frameX[n_x][n_y][0] = BGR_col_map44[x][y][0]; |
mbedobsza | 0:0def0023f900 | 225 | frameX[n_x][n_y][1] = BGR_col_map44[x][y][1]; |
mbedobsza | 0:0def0023f900 | 226 | frameX[n_x][n_y][2] = BGR_col_map44[x][y][2]; |
mbedobsza | 0:0def0023f900 | 227 | |
mbedobsza | 0:0def0023f900 | 228 | frameX[n_x+1][n_y][0] = BGR_col_map44[x][y][0]; |
mbedobsza | 0:0def0023f900 | 229 | frameX[n_x+1][n_y][1] = BGR_col_map44[x][y][1]; |
mbedobsza | 0:0def0023f900 | 230 | frameX[n_x+1][n_y][2] = BGR_col_map44[x][y][2]; |
mbedobsza | 0:0def0023f900 | 231 | |
mbedobsza | 0:0def0023f900 | 232 | frameX[n_x][n_y+1][0] = BGR_col_map44[x][y][0]; |
mbedobsza | 0:0def0023f900 | 233 | frameX[n_x][n_y+1][1] = BGR_col_map44[x][y][1]; |
mbedobsza | 0:0def0023f900 | 234 | frameX[n_x][n_y+1][2] = BGR_col_map44[x][y][2]; |
mbedobsza | 0:0def0023f900 | 235 | |
mbedobsza | 0:0def0023f900 | 236 | frameX[n_x+1][n_y+1][0] = BGR_col_map44[x][y][0]; |
mbedobsza | 0:0def0023f900 | 237 | frameX[n_x+1][n_y+1][1] = BGR_col_map44[x][y][1]; |
mbedobsza | 0:0def0023f900 | 238 | frameX[n_x+1][n_y+1][2] = BGR_col_map44[x][y][2]; |
mbedobsza | 0:0def0023f900 | 239 | |
mbedobsza | 0:0def0023f900 | 240 | |
mbedobsza | 0:0def0023f900 | 241 | |
mbedobsza | 0:0def0023f900 | 242 | } |
mbedobsza | 0:0def0023f900 | 243 | } |
mbedobsza | 0:0def0023f900 | 244 | } |
mbedobsza | 0:0def0023f900 | 245 | sendframe(frameX); |
mbedobsza | 0:0def0023f900 | 246 | displayRGB(); |
mbedobsza | 0:0def0023f900 | 247 | } |
mbedobsza | 0:0def0023f900 | 248 | |
mbedobsza | 0:0def0023f900 | 249 |