Luke Cartwright / Mbed 2 deprecated ELEC2645_Project_el18loc_nearlythere

Dependencies:   mbed

Committer:
lukeocarwright
Date:
Sat May 09 13:45:23 2020 +0000
Revision:
13:27300c533dd1
Parent:
8:f305ea78b2b1
Child:
14:9cfe0041cc4e
ADSR faders moving

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