Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: LM75B MMA7660 Servo mbed
Fork of analogintest3 by
main.cpp
00001 #include "mbed.h" 00002 #include "SerialRPCInterface.h" 00003 #include "LM75B.h" 00004 #include "C12832.h" 00005 #include "MMA7660.h" 00006 #include <time.h> 00007 #include <stdlib.h> 00008 #include "Servo.h" 00009 00010 // // // // // // // // // // // // // // // // // // // // 00011 // // // // // // //* Pennen defineren voor libs */ // // // // // 00012 C12832 glcd(p5, p7, p6, p8, p11); //Grafische display aangesloten op P5,6,7,8,11 00013 MMA7660 MMA(p28, p27); //I2C Accelerometer 00014 LM75B sensor(p28,p27); //LM75 Temp Sensor 00015 SerialRPCInterface SerialInterface(USBTX, USBRX); //USB seriele communicatie opzetten 00016 00017 PwmOut r (p23); //RGB Led op pen 23-25 00018 PwmOut g (p24); 00019 PwmOut b (p25); 00020 DigitalIn up(p15); //Joystick aangesloten op P12-16 00021 DigitalIn down(p12); 00022 DigitalIn left(p13); 00023 DigitalIn right(p16); 00024 DigitalIn fire(p14); //Drukknop joystick zit op pen P14 00025 00026 DigitalOut connectionLed(LED1); //Accel OK LED 00027 00028 BusOut leds(LED1,LED2,LED3,LED4); //Leds op MBED zelf defineren 00029 00030 // // // // // // // // // // // // // // // // // // // // 00031 // // // // // // //*Variabelen aanmaken */ // // // // // // // 00032 int potentiometer1 = 0; 00033 int potentiometer2 = 0; 00034 float Xaxis = 0; 00035 float Yaxis = 0; 00036 float Zaxis = 0; 00037 00038 int modus = 0; 00039 int kleur = 0; 00040 int rood = 0; 00041 int groen = 0; 00042 int blauw = 0; 00043 int xas = 0 ; 00044 int yas = 0 ; 00045 int potmet1 = 0; 00046 int potmet2 = 0; 00047 00048 /* 00049 char orientation; 00050 char side; 00051 char Left; 00052 char Right; 00053 char Down; 00054 char Up; 00055 char Front; 00056 char Back; 00057 */ 00058 00059 RPCVariable<int> rpc_potentiometer1(&potentiometer1,"potentiometer1"); 00060 RPCVariable<int> rpc_potentiometer2(&potentiometer2,"potentiometer2"); 00061 RPCVariable<int> rpc_xas(&xas,"xas"); 00062 RPCVariable<int> rpc_yas(&yas,"yas"); 00063 00064 RPCVariable<int> rpc_rood(&rood,"rood"); 00065 RPCVariable<int> rpc_groen(&groen,"groen"); 00066 RPCVariable<int> rpc_blauw (&blauw ,"blauw "); 00067 00068 00069 00070 AnalogIn pot2(p19); 00071 AnalogIn pot1(p20); 00072 00073 DigitalOut led(LED1); 00074 DigitalOut led2(LED2); 00075 00076 DigitalIn enter(p14); 00077 00078 PwmOut speaker(p26); 00079 00080 Servo Servo1(p21); 00081 Servo Servo2(p22); 00082 00083 void RGB_routine(); 00084 void ReadPot(); 00085 void Accelero(); 00086 void Servosturing(); 00087 void LM75_Temp(); 00088 00089 00090 00091 // // // // // // // // // // // // // // // // // // // // 00092 // // // // // // //*Begin van het hoofdprogramma */ // // // // // 00093 int main() { 00094 00095 speaker.period(0.5); 00096 r.period(0.001); 00097 g.period(0.001); 00098 b.period(0.001); 00099 00100 00101 glcd.cls(); //Clear het display 00102 glcd.locate(0,0); //Zet de cursor op X = 0 & Y = 0 00103 glcd.printf("Project Misan"); //Zet "Project Misan" op het LCD 00104 glcd.locate(0,15); //Zet de cursor op X = 0 & Y = 15 00105 glcd.printf("Use the joystick"); //Zet "Project Misan" op het LCD 00106 wait(1); //Wacht 1 seconde 00107 00108 while (1){ 00109 00110 if (fire) 00111 { 00112 while(fire){} 00113 00114 if(modus >= 5) 00115 { 00116 modus = 0; 00117 } 00118 00119 modus = modus++; 00120 speaker = 0.5; 00121 wait(0.025); 00122 speaker = 0.25; 00123 wait(0.025); 00124 speaker = 0; 00125 } 00126 00127 switch (modus) 00128 { 00129 //RGB Controller 00130 case 0: 00131 glcd.cls(); //Clear het display 00132 RGB_routine(); 00133 break; 00134 00135 //ADC Potentiometer 00136 case 1: 00137 glcd.cls(); //Clear het display 00138 ReadPot(); 00139 break; 00140 00141 //Accelerometer MMA7660 00142 case 2: 00143 glcd.cls(); //Clear het display 00144 Accelero(); 00145 break; 00146 00147 case 3: 00148 glcd.cls(); //Clear het display 00149 Servosturing(); 00150 break; 00151 00152 case 4: 00153 glcd.cls(); //Clear het display 00154 LM75_Temp(); 00155 break; 00156 } 00157 } 00158 } 00159 00160 00161 00162 00163 // // // // // // // // // // // // // // // // // // // // // // // // // 00164 // // // // // // //* RGB routine voor kleurwijzigen met de Joystick */ // // // // // 00165 void RGB_routine() 00166 { 00167 00168 00169 if (right) 00170 { 00171 if (kleur < 2) 00172 { 00173 kleur = kleur++; 00174 } 00175 if (kleur == 2) 00176 { 00177 kleur = 0; 00178 } 00179 } 00180 00181 if (left) 00182 { 00183 if (kleur > 0) 00184 { 00185 kleur = kleur--; 00186 } 00187 if (kleur == 0) 00188 { 00189 kleur = 2; 00190 } 00191 } 00192 00193 if (up) 00194 { 00195 if(kleur == 0 & rood <1) 00196 { 00197 rood = rood + 0.05; 00198 } 00199 if(kleur == 0 && rood == 1) 00200 { 00201 rood = 0; 00202 } 00203 if(kleur == 1 && groen <1) 00204 { 00205 groen = groen + 0.05; 00206 } 00207 if(kleur == 1 && groen == 1) 00208 { 00209 groen = 0; 00210 } 00211 if(kleur == 2 && blauw <1) 00212 { 00213 blauw = blauw + 0.05; 00214 } 00215 if(kleur == 2 && blauw == 1) 00216 { 00217 blauw = 0; 00218 } 00219 } 00220 00221 if (down) 00222 { 00223 if(kleur == 0 && rood <0) 00224 { 00225 rood = rood - 0.05; 00226 } 00227 if(kleur == 0 && rood == 0) 00228 { 00229 rood = 1; 00230 } 00231 if(kleur == 1 && groen <0) 00232 { 00233 groen = groen - 0.05; 00234 } 00235 if(kleur == 1 && groen == 0) 00236 { 00237 groen = 1; 00238 } 00239 if(kleur == 2 && blauw <0) 00240 { 00241 blauw = blauw - 0.05; 00242 } 00243 if(kleur == 2 && blauw == 0) 00244 { 00245 blauw = 1; 00246 } 00247 } 00248 00249 00250 00251 00252 00253 /* if (up) 00254 { 00255 switch (kleur) 00256 { 00257 case 0: 00258 rood += 0.05; 00259 break; 00260 case 1: 00261 groen += 0.05; 00262 break; 00263 case 2: 00264 blauw += 0.05; 00265 break; 00266 } 00267 00268 } 00269 00270 if (down) 00271 { 00272 switch (kleur) 00273 { 00274 case 0: 00275 rood -= 0.05; 00276 break; 00277 case 1: 00278 groen -= 0.05; 00279 break; 00280 case 2: 00281 blauw -= 0.05; 00282 break; 00283 } 00284 } 00285 00286 if (right) 00287 { 00288 switch (kleur) 00289 { 00290 case 0: 00291 kleur += 1; 00292 break; 00293 case 1: 00294 kleur += 1; 00295 break; 00296 case 2: 00297 kleur = 0; 00298 break; 00299 } 00300 00301 } 00302 00303 if (left) 00304 { 00305 switch (kleur) 00306 { 00307 case 0: 00308 kleur = 2; 00309 break; 00310 case 1: 00311 kleur -= 1; 00312 break; 00313 case 2: 00314 kleur -= 1; 00315 break; 00316 } 00317 00318 } 00319 00320 00321 */ 00322 00323 00324 00325 00326 00327 00328 00329 00330 00331 00332 00333 00334 glcd.locate(0,0); //Zet de cursor op X = 0 & Y = 0 00335 glcd.printf("R: %i", up); 00336 glcd.locate(0,9); //Zet de cursor op X = 0 & Y = 10 00337 glcd.printf("G: %i", down); 00338 glcd.locate(0,18); //Zet de cursor op X = 0 & Y = 18 00339 glcd.printf("B: %i", blauw); 00340 wait(0.5); 00341 00342 } 00343 00344 // // // // // // // // // // // // // // // // // // // // // // // // // 00345 // // // // // // //* Inlezen en visualiseren van de potentiometers */ // // // // // 00346 void ReadPot() 00347 { 00348 potentiometer1 = pot1*100; //steek de waarde van de Potentiometer1 in ai1 00349 potentiometer2 = pot2*100; //steek de waarde van de Potentiometer2 in ai2 00350 00351 glcd.locate(0,0); //Zet de cursor op X = 0 & Y = 0 00352 glcd.printf("Pot 1: %i ", potentiometer1); //Print de waarde van de potententiometer 1 op het display 00353 glcd.locate(0,10); //Zet de cursor op X = 0 & Y = 10 00354 glcd.printf("Pot 2: %i ", potentiometer2); //Print de waarde van de potententiometer 2 op het display 00355 wait(0.5); //Wacht 1 seconde 00356 } 00357 00358 00359 void Accelero() 00360 { 00361 if (MMA.testConnection()) 00362 { 00363 leds = 1; 00364 } 00365 00366 Xaxis = MMA.x(); 00367 Yaxis = MMA.y(); 00368 Zaxis = MMA.z(); 00369 xas = Xaxis*100 ; 00370 yas = Yaxis*100 ; 00371 00372 glcd.locate(0,0); //Zet de cursor op X = 0 & Y = 0 00373 glcd.printf("X-Axis: %f G", Xaxis); 00374 glcd.locate(0,9); //Zet de cursor op X = 0 & Y = 10 00375 glcd.printf("Y-Axis: %f G", Yaxis); 00376 glcd.locate(0,18); //Zet de cursor op X = 0 & Y = 18 00377 glcd.printf("Z-Axis: %f G", Zaxis); 00378 wait(1); 00379 00380 } 00381 00382 00383 void Servosturing() 00384 { 00385 00386 potentiometer1 = pot1; //steek de waarde van de Potentiometer1 in ai1 00387 potentiometer2 = pot2; //steek de waarde van de Potentiometer2 in ai2 00388 wait(0.1); 00389 00390 Servo1.write(potentiometer1); 00391 Servo2.write(potentiometer2); 00392 00393 glcd.locate(0,0); //Zet de cursor op X = 0 & Y = 0 00394 glcd.printf("Servo-1: %f", Servo1); 00395 glcd.locate(0,10); //Zet de cursor op X = 0 & Y = 10 00396 glcd.printf("Servo-2: %f", Servo2); 00397 00398 wait(0.5); 00399 } 00400 00401 void LM75_Temp() 00402 { 00403 //Try to open the LM75B 00404 glcd.locate(0,0); //Zet de cursor op X = 0 & Y = 0 00405 glcd.printf("Device detected!"); 00406 glcd.locate(0,10); 00407 glcd.printf("Temp = %.3f", sensor); 00408 wait(0.5); 00409 } 00410 00411 00412 00413 00414 00415 00416 00417 00418 00419 00420 00421 00422 00423 00424 00425 00426 00427 00428 /*switch (side) 00429 { 00430 case "Front": 00431 switch (orientation) 00432 { 00433 case "Left": 00434 glcd.locate(0,27); //Zet de cursor op X = 0 & Y = 10 00435 glcd.printf("Front Left"); 00436 break; 00437 00438 case "Right": 00439 glcd.locate(0,27); //Zet de cursor op X = 0 & Y = 10 00440 glcd.printf("Front Right"); 00441 break; 00442 00443 case "Down": 00444 glcd.locate(0,27); //Zet de cursor op X = 0 & Y = 10 00445 glcd.printf("Front Down"); 00446 break; 00447 00448 case "Up": 00449 glcd.locate(0,27); //Zet de cursor op X = 0 & Y = 10 00450 glcd.printf("Front Up"); 00451 break; 00452 } 00453 break; 00454 00455 00456 case "Back": 00457 switch (orientation) 00458 { 00459 case "Left": 00460 glcd.locate(0,27); //Zet de cursor op X = 0 & Y = 10 00461 glcd.printf("Back Left"); 00462 break; 00463 00464 case "Right": 00465 glcd.locate(0,27); //Zet de cursor op X = 0 & Y = 10 00466 glcd.printf("Back Right"); 00467 break; 00468 00469 case "Down": 00470 glcd.locate(0,27); //Zet de cursor op X = 0 & Y = 10 00471 glcd.printf("Back Down"); 00472 break; 00473 00474 case "Up": 00475 glcd.locate(0,27); //Zet de cursor op X = 0 & Y = 10 00476 glcd.printf("Back Up"); 00477 break; 00478 } 00479 break; 00480 } */ 00481
Generated on Sat Jul 16 2022 16:20:13 by
