ELEC2645 (2019/20) / Mbed 2 deprecated el18loc_final

Dependencies:   mbed

Committer:
lukeocarwright
Date:
Tue May 19 18:38:33 2020 +0000
Revision:
15:1c67f064278e
Parent:
14:9cfe0041cc4e
Child:
18:204cd747b54a
Fixed Tri wavetable issue to get tri wave out. Added more slow debug elements.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lukeocarwright 7:33cb5f2db1ee 1 #include "mbed.h"
lukeocarwright 7:33cb5f2db1ee 2 #include "Front.h"
lukeocarwright 7:33cb5f2db1ee 3
lukeocarwright 14:9cfe0041cc4e 4 //Objects-----------------------------------------------------------------------
lukeocarwright 14:9cfe0041cc4e 5 Sound sound;
lukeocarwright 14:9cfe0041cc4e 6
lukeocarwright 14:9cfe0041cc4e 7 //Sprites-----------------------------------------------------------------------
lukeocarwright 7:33cb5f2db1ee 8 const int fader[35][5] = {
lukeocarwright 7:33cb5f2db1ee 9 { 1,1,1,1,1 },
lukeocarwright 7:33cb5f2db1ee 10 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 11 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 12 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 13 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 14 { 1,1,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 15 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 16 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 17 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 18 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 19 { 1,1,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 20 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 21 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 22 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 23 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 24 { 1,1,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 25 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 26 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 27 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 28 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 29 { 1,1,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 30 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 31 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 32 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 33 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 34 { 1,1,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 35 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 36 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 37 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 38 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 39 { 1,1,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 40 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 41 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 42 { 0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 43 { 1,1,1,1,1 },
lukeocarwright 7:33cb5f2db1ee 44 };
lukeocarwright 7:33cb5f2db1ee 45
lukeocarwright 14:9cfe0041cc4e 46 const int sin_wav[6][28] = {//sub 1 sin sprite
lukeocarwright 7:33cb5f2db1ee 47 { 0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0 },
lukeocarwright 7:33cb5f2db1ee 48 { 0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 49 { 1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0 },
lukeocarwright 7:33cb5f2db1ee 50 { 0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1 },
lukeocarwright 7:33cb5f2db1ee 51 { 0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0 },
lukeocarwright 7:33cb5f2db1ee 52 { 0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0 },
lukeocarwright 7:33cb5f2db1ee 53 };
lukeocarwright 14:9cfe0041cc4e 54 const int tri_wav[6][28] = {//sub 2 tri sprite
lukeocarwright 7:33cb5f2db1ee 55 { 0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0 },
lukeocarwright 7:33cb5f2db1ee 56 { 0,0,1,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0 },
lukeocarwright 7:33cb5f2db1ee 57 { 0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0 },
lukeocarwright 7:33cb5f2db1ee 58 { 1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0,0,0,1,0,0,0,0,0,1,0 },
lukeocarwright 7:33cb5f2db1ee 59 { 0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,1 },
lukeocarwright 7:33cb5f2db1ee 60 { 0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0 },
lukeocarwright 7:33cb5f2db1ee 61 };
lukeocarwright 14:9cfe0041cc4e 62 const int square_wav[6][28] = {//sub 3 sqr sprite
lukeocarwright 7:33cb5f2db1ee 63 { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
lukeocarwright 7:33cb5f2db1ee 64 { 1,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1 },
lukeocarwright 7:33cb5f2db1ee 65 { 0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0 },
lukeocarwright 7:33cb5f2db1ee 66 { 0,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0,1,0,0,0 },
lukeocarwright 7:33cb5f2db1ee 67 { 0,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0,1,1,1,1,1,0,0,0 },
lukeocarwright 7:33cb5f2db1ee 68 { 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 },
lukeocarwright 7:33cb5f2db1ee 69 };
lukeocarwright 14:9cfe0041cc4e 70 volatile int g_isr_flag;
lukeocarwright 14:9cfe0041cc4e 71
lukeocarwright 7:33cb5f2db1ee 72 //constructor/destructor
lukeocarwright 7:33cb5f2db1ee 73 Front::Front()
lukeocarwright 7:33cb5f2db1ee 74 {
lukeocarwright 7:33cb5f2db1ee 75 }
lukeocarwright 7:33cb5f2db1ee 76 Front::~Front()
lukeocarwright 7:33cb5f2db1ee 77 {
lukeocarwright 7:33cb5f2db1ee 78 }
lukeocarwright 7:33cb5f2db1ee 79 //PUBLIC------------------------------------------------------------------------
lukeocarwright 8:f305ea78b2b1 80
lukeocarwright 8:f305ea78b2b1 81 void Front::frontrun(N5110 &lcd, Gamepad &pad, int submenu)
lukeocarwright 14:9cfe0041cc4e 82 {
lukeocarwright 14:9cfe0041cc4e 83 //printf("G_ISR_FLAG= %d\n",g_isr_flag);
lukeocarwright 13:27300c533dd1 84 frontsetup(lcd, pad, submenu, true);
lukeocarwright 8:f305ea78b2b1 85 menuflag=1;
lukeocarwright 13:27300c533dd1 86 used=1;
lukeocarwright 13:27300c533dd1 87 a=17;
lukeocarwright 13:27300c533dd1 88 d=17;
lukeocarwright 13:27300c533dd1 89 s=17;
lukeocarwright 13:27300c533dd1 90 r=17;
lukeocarwright 14:9cfe0041cc4e 91 out=sound.sound_main(true,submenu,440);
lukeocarwright 14:9cfe0041cc4e 92
lukeocarwright 8:f305ea78b2b1 93 while (menuflag==1) {
lukeocarwright 14:9cfe0041cc4e 94 #ifdef SLOW_TIME
lukeocarwright 14:9cfe0041cc4e 95 printf(":=:");
lukeocarwright 14:9cfe0041cc4e 96 #endif
lukeocarwright 14:9cfe0041cc4e 97 if (g_isr_flag == 1) {
lukeocarwright 14:9cfe0041cc4e 98 pad.write_u16(out);
lukeocarwright 14:9cfe0041cc4e 99 #ifdef SLOW_TIME
lukeocarwright 14:9cfe0041cc4e 100 printf("out= %u\n",out);
lukeocarwright 14:9cfe0041cc4e 101 #endif
lukeocarwright 14:9cfe0041cc4e 102 out=sound.sound_main(false,submenu,440);
lukeocarwright 14:9cfe0041cc4e 103 g_isr_flag=0;
lukeocarwright 14:9cfe0041cc4e 104 }
lukeocarwright 13:27300c533dd1 105 dir=pad.get_direction();
lukeocarwright 13:27300c533dd1 106 if (dir!=dir_1) {
lukeocarwright 13:27300c533dd1 107 printf("dir =%d\n",dir); //debug
lukeocarwright 13:27300c533dd1 108 if(dir==3) {
lukeocarwright 13:27300c533dd1 109 used++;
lukeocarwright 13:27300c533dd1 110 if (used>4) {
lukeocarwright 13:27300c533dd1 111 used=4;
lukeocarwright 13:27300c533dd1 112 }
lukeocarwright 13:27300c533dd1 113 }
lukeocarwright 13:27300c533dd1 114 if (dir==7) {
lukeocarwright 13:27300c533dd1 115 used--;
lukeocarwright 13:27300c533dd1 116 if(used<1) {
lukeocarwright 13:27300c533dd1 117 used=1;
lukeocarwright 13:27300c533dd1 118 }
lukeocarwright 13:27300c533dd1 119 }
lukeocarwright 13:27300c533dd1 120 if (dir==1) {
lukeocarwright 13:27300c533dd1 121 if (used==1) {
lukeocarwright 13:27300c533dd1 122 a=incrament_adsr(used,a,1);
lukeocarwright 13:27300c533dd1 123 }
lukeocarwright 13:27300c533dd1 124 if (used==2) {
lukeocarwright 13:27300c533dd1 125 d=incrament_adsr(used,d,1);
lukeocarwright 13:27300c533dd1 126 }
lukeocarwright 13:27300c533dd1 127 if (used==3) {
lukeocarwright 13:27300c533dd1 128 s=incrament_adsr(used,s,1);
lukeocarwright 13:27300c533dd1 129 }
lukeocarwright 13:27300c533dd1 130 if (used==4) {
lukeocarwright 13:27300c533dd1 131 r=incrament_adsr(used,r,1);
lukeocarwright 13:27300c533dd1 132 }
lukeocarwright 13:27300c533dd1 133 }
lukeocarwright 13:27300c533dd1 134
lukeocarwright 13:27300c533dd1 135 if (dir==5) {
lukeocarwright 13:27300c533dd1 136 if (used==1) {
lukeocarwright 13:27300c533dd1 137 a=incrament_adsr(used,a,-1);
lukeocarwright 13:27300c533dd1 138 }
lukeocarwright 13:27300c533dd1 139 if (used==2) {
lukeocarwright 13:27300c533dd1 140 d=incrament_adsr(used,d,-1);
lukeocarwright 13:27300c533dd1 141 }
lukeocarwright 13:27300c533dd1 142 if (used==3) {
lukeocarwright 13:27300c533dd1 143 s=incrament_adsr(used,s,-1);
lukeocarwright 13:27300c533dd1 144 }
lukeocarwright 13:27300c533dd1 145 if (used==4) {
lukeocarwright 13:27300c533dd1 146 r=incrament_adsr(used,r,-1);
lukeocarwright 13:27300c533dd1 147 }
lukeocarwright 13:27300c533dd1 148 }
lukeocarwright 13:27300c533dd1 149
lukeocarwright 13:27300c533dd1 150 if (pad.start_pressed()) { //go back menu
lukeocarwright 13:27300c533dd1 151 // printf("start pressed\n");
lukeocarwright 13:27300c533dd1 152 printf("Waveforms Sub selected\n"); //debug
lukeocarwright 13:27300c533dd1 153 wait_ms(200); //debounce
lukeocarwright 13:27300c533dd1 154 menuflag=0; //sets flag
lukeocarwright 13:27300c533dd1 155 }
lukeocarwright 13:27300c533dd1 156 frontsetup(lcd,pad,submenu,false);
lukeocarwright 13:27300c533dd1 157 printsliders(lcd,a,d,s,r,used);
lukeocarwright 13:27300c533dd1 158 wait_ms(200);
lukeocarwright 8:f305ea78b2b1 159 }
lukeocarwright 13:27300c533dd1 160 dir=dir_1;
lukeocarwright 14:9cfe0041cc4e 161 sleep();
lukeocarwright 8:f305ea78b2b1 162 }
lukeocarwright 8:f305ea78b2b1 163 }
lukeocarwright 8:f305ea78b2b1 164
lukeocarwright 8:f305ea78b2b1 165 //PRIVATE-----------------------------------------------------------------------
lukeocarwright 8:f305ea78b2b1 166
lukeocarwright 13:27300c533dd1 167 void Front::frontsetup(N5110 &lcd, Gamepad &pad, int submenu, bool initial)
lukeocarwright 7:33cb5f2db1ee 168 {
lukeocarwright 13:27300c533dd1 169 if (initial==true) {
lukeocarwright 13:27300c533dd1 170 printsliders(lcd,17,17,17,17,1);
lukeocarwright 13:27300c533dd1 171 }
lukeocarwright 7:33cb5f2db1ee 172 lcd.clear();
lukeocarwright 7:33cb5f2db1ee 173 lcd.printString("A D S R",3,5);
lukeocarwright 7:33cb5f2db1ee 174 printfader(lcd,3,3);
lukeocarwright 7:33cb5f2db1ee 175 printfader(lcd,15,3);
lukeocarwright 7:33cb5f2db1ee 176 printfader(lcd,27,3);
lukeocarwright 7:33cb5f2db1ee 177 printfader(lcd,39,3);
lukeocarwright 7:33cb5f2db1ee 178 lcd.drawRect(50,3,30,8,FILL_TRANSPARENT);
lukeocarwright 7:33cb5f2db1ee 179 printwav(lcd,submenu);
lukeocarwright 7:33cb5f2db1ee 180 lcd.refresh();
lukeocarwright 15:1c67f064278e 181 }
lukeocarwright 13:27300c533dd1 182
lukeocarwright 13:27300c533dd1 183 void Front::printsliders(N5110 &lcd, int a, int d, int s, int r, int used)
lukeocarwright 7:33cb5f2db1ee 184 {
lukeocarwright 13:27300c533dd1 185 if(used==0) {
lukeocarwright 13:27300c533dd1 186 printslider(lcd,3,a,false);
lukeocarwright 13:27300c533dd1 187 printslider(lcd,15,d,false);
lukeocarwright 13:27300c533dd1 188 printslider(lcd,27,s,false);
lukeocarwright 13:27300c533dd1 189 printslider(lcd,39,r,false);
lukeocarwright 13:27300c533dd1 190 }
lukeocarwright 13:27300c533dd1 191 if(used==1) {
lukeocarwright 13:27300c533dd1 192 printslider(lcd,3,a,true);
lukeocarwright 13:27300c533dd1 193 printslider(lcd,15,d,false);
lukeocarwright 13:27300c533dd1 194 printslider(lcd,27,s,false);
lukeocarwright 13:27300c533dd1 195 printslider(lcd,39,r,false);
lukeocarwright 13:27300c533dd1 196 }
lukeocarwright 13:27300c533dd1 197 if(used==2) {
lukeocarwright 13:27300c533dd1 198 printslider(lcd,3,a,false);
lukeocarwright 13:27300c533dd1 199 printslider(lcd,15,d,true);
lukeocarwright 13:27300c533dd1 200 printslider(lcd,27,s,false);
lukeocarwright 13:27300c533dd1 201 printslider(lcd,39,r,false);
lukeocarwright 13:27300c533dd1 202 }
lukeocarwright 13:27300c533dd1 203 if(used==3) {
lukeocarwright 13:27300c533dd1 204 printslider(lcd,3,a,false);
lukeocarwright 13:27300c533dd1 205 printslider(lcd,15,d,false);
lukeocarwright 13:27300c533dd1 206 printslider(lcd,27,s,true);
lukeocarwright 13:27300c533dd1 207 printslider(lcd,39,r,false);
lukeocarwright 13:27300c533dd1 208 }
lukeocarwright 13:27300c533dd1 209 if(used==4) {
lukeocarwright 13:27300c533dd1 210 printslider(lcd,3,a,false);
lukeocarwright 13:27300c533dd1 211 printslider(lcd,15,d,false);
lukeocarwright 13:27300c533dd1 212 printslider(lcd,27,s,false);
lukeocarwright 13:27300c533dd1 213 printslider(lcd,39,r,true);
lukeocarwright 13:27300c533dd1 214 }
lukeocarwright 13:27300c533dd1 215 lcd.refresh();
lukeocarwright 7:33cb5f2db1ee 216 }
lukeocarwright 13:27300c533dd1 217
lukeocarwright 13:27300c533dd1 218 void Front::printslider(N5110 &lcd, int x_val, int y_val, bool use)
lukeocarwright 13:27300c533dd1 219 {
lukeocarwright 13:27300c533dd1 220 if (use==true) {
lukeocarwright 13:27300c533dd1 221 lcd.drawRect(x_val,37-y_val,5,2,FILL_BLACK);
lukeocarwright 13:27300c533dd1 222 }
lukeocarwright 13:27300c533dd1 223 if (use==false) {
lukeocarwright 13:27300c533dd1 224 lcd.drawRect(x_val,37-y_val,5,1,FILL_BLACK);
lukeocarwright 13:27300c533dd1 225 }
lukeocarwright 13:27300c533dd1 226 }
lukeocarwright 13:27300c533dd1 227
lukeocarwright 13:27300c533dd1 228
lukeocarwright 7:33cb5f2db1ee 229 void Front::printfader(N5110 &lcd, int x, int y)
lukeocarwright 7:33cb5f2db1ee 230 {
lukeocarwright 7:33cb5f2db1ee 231 // x origin, y origin, rows, cols, sprite
lukeocarwright 7:33cb5f2db1ee 232 lcd.drawSprite(x,y,35,5,(int *)fader);
lukeocarwright 7:33cb5f2db1ee 233 }
lukeocarwright 7:33cb5f2db1ee 234
lukeocarwright 7:33cb5f2db1ee 235 void Front::printwav(N5110 &lcd, int submenu)
lukeocarwright 7:33cb5f2db1ee 236 {
lukeocarwright 7:33cb5f2db1ee 237 if (submenu==1) {
lukeocarwright 7:33cb5f2db1ee 238 // x origin, y origin, rows, cols, sprite
lukeocarwright 7:33cb5f2db1ee 239 lcd.drawSprite(51,4,6,28,(int *)sin_wav);
lukeocarwright 7:33cb5f2db1ee 240 }
lukeocarwright 7:33cb5f2db1ee 241 if (submenu==2) {
lukeocarwright 7:33cb5f2db1ee 242 // x origin, y origin, rows, cols, sprite
lukeocarwright 7:33cb5f2db1ee 243 lcd.drawSprite(51,4,6,28,(int *)tri_wav);
lukeocarwright 7:33cb5f2db1ee 244 }
lukeocarwright 7:33cb5f2db1ee 245 if (submenu==3) {
lukeocarwright 7:33cb5f2db1ee 246 // x origin, y origin, rows, cols, sprite
lukeocarwright 7:33cb5f2db1ee 247 lcd.drawSprite(51,4,6,28,(int *)square_wav);
lukeocarwright 7:33cb5f2db1ee 248 }
lukeocarwright 13:27300c533dd1 249 }
lukeocarwright 13:27300c533dd1 250
lukeocarwright 13:27300c533dd1 251 int Front::incrament_adsr(int used, int adsr, int ud)
lukeocarwright 13:27300c533dd1 252 {
lukeocarwright 13:27300c533dd1 253 if (ud==1) {
lukeocarwright 13:27300c533dd1 254 adsr++;
lukeocarwright 13:27300c533dd1 255 if (adsr>35) {
lukeocarwright 13:27300c533dd1 256 adsr--;
lukeocarwright 13:27300c533dd1 257 }
lukeocarwright 13:27300c533dd1 258 }
lukeocarwright 13:27300c533dd1 259 if (ud==-1) {
lukeocarwright 13:27300c533dd1 260 adsr--;
lukeocarwright 13:27300c533dd1 261 if (adsr<1) {
lukeocarwright 13:27300c533dd1 262 adsr++;
lukeocarwright 13:27300c533dd1 263 }
lukeocarwright 13:27300c533dd1 264 }
lukeocarwright 13:27300c533dd1 265 return(adsr);
lukeocarwright 7:33cb5f2db1ee 266 }