Project DataAquisitie
Dependencies: LM75B MMA7660 Servo mbed
Fork of analogintest3 by
Diff: main.cpp
- Revision:
- 2:b3eddbd12635
- Parent:
- 1:2b6bdf677573
- Child:
- 3:194d842b7ba1
--- a/main.cpp Mon May 18 20:04:55 2015 +0000 +++ b/main.cpp Tue May 19 11:04:00 2015 +0000 @@ -6,14 +6,14 @@ #include <time.h> #include <stdlib.h> #include "Servo.h" - + // // // // // // // // // // // // // // // // // // // // // // // // // // //* Pennen defineren voor libs */ // // // // // C12832 glcd(p5, p7, p6, p8, p11); //Grafische display aangesloten op P5,6,7,8,11 MMA7660 MMA(p28, p27); //I2C Accelerometer LM75B LM75(p28,p27); //LM75 Temp Sensor SerialRPCInterface SerialInterface(USBTX, USBRX); //USB seriele communicatie opzetten - + PwmOut r (p23); //RGB Led op pen 23-25 PwmOut g (p24); PwmOut b (p25); @@ -22,11 +22,11 @@ DigitalIn left(p13); DigitalIn right(p16); DigitalIn fire(p14); //Drukknop joystick zit op pen P14 - + DigitalOut connectionLed(LED1); //Accel OK LED - + BusOut leds(LED1,LED2,LED3,LED4); //Leds op MBED zelf defineren - + // // // // // // // // // // // // // // // // // // // // // // // // // // //*Variabelen aanmaken */ // // // // // // // float potentiometer1 = 0; @@ -34,7 +34,7 @@ float Xaxis = 0; float Yaxis = 0; float Zaxis = 0; - + int modus = 0; int alarm1 = 0; int alarm2 = 0; @@ -42,47 +42,49 @@ int rood = 0; int groen = 0; int blauw = 0; - + char orientation; char side; - + char Left; char Right; char Down; char Up; char Front; char Back; - - + + RPCVariable<float> rpc_ai1(&potentiometer1,"potentiometer1"); RPCVariable<float> rpc_ai2(&potentiometer2,"potentiometer2"); RPCVariable<int> rpc_alarm1(&alarm1,"alarm1"); RPCVariable<int> rpc_alarm2(&alarm2,"alarm2"); - + +RPCVariable<int> rpc_rood(&rood,"rood"); +RPCVariable<int> rpc_groen(&groen,"groen"); +RPCVariable<int> rpc_blauw (&blauw ,"blauw "); + AnalogIn pot2(p19); AnalogIn pot1(p20); - + DigitalOut led(LED1); DigitalOut led2(LED2); - + DigitalIn enter(p14); - + PwmOut speaker(p26); -PwmOut Zaxis_p(p23); -PwmOut Zaxis_n(p24); - + Servo Servo1(p21); Servo Servo2(p22); - + void RGB_routine(); void ReadPot(); void Accelero(); void Servosturing(); - + // // // // // // // // // // // // // // // // // // // // // // // // // // //*Begin van het hoofdprogramma */ // // // // // int main() { - + speaker.period(0.5); r.period(0.001); g.period(0.001); @@ -90,61 +92,62 @@ glcd.cls(); //Clear het display - glcd.locate(0,3); //Zet de cursor op X = 0 & Y = 3 + glcd.locate(0,0); //Zet de cursor op X = 0 & Y = 0 glcd.printf("Project Misan"); //Zet "Project Misan" op het LCD - wait(1); //Wacht 1 seconde - glcd.printf("Use the joystick"); //Zet "Project Misan" op het LCD + glcd.locate(0,15); //Zet de cursor op X = 0 & Y = 15 + glcd.printf("Use the joystick"); //Zet "Project Misan" op het LCD + wait(1); //Wacht 1 seconde while (1){ if (fire) { while(fire){} + + if(modus >= 4) + { + modus = 0; + } + modus = modus++; - speaker = 0.5; + speaker = 0.5; + wait(0.025); + speaker = 0.25; + wait(0.025); + speaker = 0; } switch (modus) { //RGB Controller - case 0: - glcd.cls(); //Clear het display - glcd.locate(0,0); //Zet de cursor op X = 0 & Y = 0 - glcd.printf("RGB Led controller"); + case 0: + glcd.cls(); //Clear het display RGB_routine(); break; //ADC Potentiometer case 1: - glcd.cls(); //Clear het display - glcd.locate(0,0); - glcd.printf("Read Potentiometers"); + glcd.cls(); //Clear het display ReadPot(); break; //Accelerometer MMA7660 - case 2: - glcd.cls(); //Clear het display - glcd.locate(0,0); - glcd.printf("MMM7660"); - glcd.locate(0,10); - glcd.printf("Accelerometer"); + case 2: + glcd.cls(); //Clear het display Accelero(); break; - case 3: - glcd.cls(); //Clear het display - glcd.locate(0,0); - glcd.printf("Servo"); + case 3: + glcd.cls(); //Clear het display Servosturing(); break; } } } - - - - + + + + // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //* RGB routine voor kleurwijzigen met de Joystick */ // // // // // void RGB_routine() @@ -154,13 +157,13 @@ switch (kleur) { case 0: - r = 1.0 - (rood += 0.05); + rood += 0.05; break; case 1: - g = 1.0 - (groen += 0.05); + groen += 0.05; break; case 2: - b = 1.0 - (blauw += 0.05); + blauw += 0.05; break; } @@ -171,13 +174,13 @@ switch (kleur) { case 0: - r = 1.0 - (rood -= 0.05); + rood -= 0.05; break; case 1: - g = 1.0 - (groen -= 0.05); + groen -= 0.05; break; case 2: - b = 1.0 - (blauw -= 0.05); + blauw -= 0.05; break; } } @@ -214,9 +217,32 @@ break; } - } + } + + + + + + + + + + + + + + + + glcd.locate(0,0); //Zet de cursor op X = 0 & Y = 0 + glcd.printf("R: %i", r); + glcd.locate(0,9); //Zet de cursor op X = 0 & Y = 10 + glcd.printf("G: %i", g); + glcd.locate(0,18); //Zet de cursor op X = 0 & Y = 18 + glcd.printf("B: %i", b); + wait(0.5); + } - + // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // //* Inlezen en visualiseren van de potentiometers */ // // // // // void ReadPot() @@ -224,14 +250,14 @@ potentiometer1 = pot1; //steek de waarde van de Potentiometer1 in ai1 potentiometer2 = pot2; //steek de waarde van de Potentiometer2 in ai2 - glcd.cls(); glcd.locate(0,0); //Zet de cursor op X = 0 & Y = 0 glcd.printf("Pot 1: %f ", potentiometer1); //Print de waarde van de potententiometer 1 op het display glcd.locate(0,10); //Zet de cursor op X = 0 & Y = 10 - glcd.printf("Pot 2: %f ", potentiometer2); //Print de waarde van de potententiometer 2 op het display + glcd.printf("Pot 2: %f ", potentiometer2); //Print de waarde van de potententiometer 2 op het display + wait(0.5); //Wacht 1 seconde } - - + + void Accelero() { if (MMA.testConnection()) @@ -243,7 +269,6 @@ Yaxis = MMA.y(); Zaxis = MMA.z(); - glcd.cls(); glcd.locate(0,0); //Zet de cursor op X = 0 & Y = 0 glcd.printf("X-Axis: %f G", Xaxis); glcd.locate(0,9); //Zet de cursor op X = 0 & Y = 10 @@ -251,15 +276,10 @@ glcd.locate(0,18); //Zet de cursor op X = 0 & Y = 18 glcd.printf("Z-Axis: %f G", Zaxis); wait(1); - - orientation = MMA.getOrientation(); - side = MMA.getSide(); - - glcd.locate(0,27); //Zet de cursor op X = 0 & Y = 0 - glcd.printf("Side: %s Orientation: %s", side, orientation); + } - - + + void Servosturing() { @@ -267,36 +287,36 @@ potentiometer2 = pot2; //steek de waarde van de Potentiometer2 in ai2 wait(0.1); - Servo1 = potentiometer1; - Servo2 = potentiometer2; + Servo1.write(potentiometer1); + Servo2.write(potentiometer2); - glcd.cls(); glcd.locate(0,0); //Zet de cursor op X = 0 & Y = 0 glcd.printf("Servo-1: %f", Servo1); glcd.locate(0,10); //Zet de cursor op X = 0 & Y = 10 - glcd.printf("Servo-1: %f", Servo2); - - wait(1); + glcd.printf("Servo-21 %f", Servo2); + + wait(0.5); } - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + /*switch (side) { case "Front": @@ -323,7 +343,7 @@ break; } break; - + case "Back": switch (orientation) @@ -349,5 +369,4 @@ break; } break; - } */ - + } */ \ No newline at end of file