Dependencies: Servo TextLCD mbed
Diff: main.cpp
- Revision:
- 4:1a6e5f38f0d9
- Parent:
- 3:dd4efdfbbf01
- Child:
- 5:da214688a308
--- a/main.cpp Fri Jun 17 10:58:45 2016 +0000 +++ b/main.cpp Fri Jun 17 14:54:33 2016 +0000 @@ -33,12 +33,13 @@ AnalogIn analogX(A1); //Analog in for x potentiometer AnalogIn analogY(A3); //Analog in for y potentiometer -float vitesse = 0.001; //--------------------------------------------- CHANGE IT TO REDUCE/INCREASE SERVOMOTORS SPEED -------------------- +float vitesse = 0.001; //------------------------------------------- CHANGE IT TO REDUCE/INCREASE SERVOMOTORS SPEED -------------------- int page; int i = 0; int disp = 0; float xPos = 0; float yPos = 0; +int ok = 0; int main(){ @@ -50,13 +51,13 @@ lcd.printf("Clement BALLOT"); servoRL = 0; servoHL = 0; - while(i != 50){ + while(i != 5){ ledY = 1; ledV = 0; - wait(0.05); + wait(0.5); ledY = 0; ledV = 1; - wait(0.05); + wait(0.5); i = i++; } ledY = 0; @@ -123,27 +124,41 @@ lcd.printf("Press a button.."); lcd.locate(0, 1); lcd.printf("Currently : P%d ", page); - wait(5); - - if(menuR == 1) { - page = page++; + i = 0; + while(i!=5){ + wait(0.5); + ledV = 0; + wait(0.5); + ledV = 1; + i = i++; } - else if(menuL == 1){ - page = page--; - } - - if(page >5){ - page = 1; - } - else if(page<1){ + + if(menuR == 1 && menuL == 1 && ok == 0){ page = 5; } - - ledV = 0; - ledY = 1; + + else if(menuL == 1){ + if(page == 1){ + page = 4; + } + else{ + page = page--; + } + } + else if(menuR == 1){ + if(page == 4){ + page = 1; + } + else{ + page = page++; + } + } + lcd.locate(0, 1); lcd.printf("OK ! Next : P%d ", page); wait(3); + ledV = 0; + ledY = 1; lcd.cls(); lcd.locate(0, 0); lcd.printf("Loading P%d...", page); @@ -160,14 +175,13 @@ wait(3); lcd.locate(3, 1); lcd.printf(": x servo "); - while(xPos<50){ + while(xPos<0.50){ lcd.locate(0, 1); xPos = xPos+0.01; disp = xPos*100; - servoHL = xPos; + servoRL = xPos; lcd.printf("%3d", disp); - i = i++; - wait(vitesse); + wait(vitesse*10); } wait(1); @@ -182,7 +196,7 @@ ledV = 1; wait(1); lcd.locate(0,1); - while(yPos<100){ + while(yPos<1.00){ lcd.locate(0,1); yPos = yPos + 0.01; disp = yPos*100; @@ -360,26 +374,58 @@ lcd.printf("P5 : manual mode"); lcd.locate(0,1); lcd.printf("Button : exit"); - wait(3); + wait(1); + int j=0; + lcd.locate(15, 1); + while(j < 60){ + ledV = 1; + ledY = 0; + i = rand(); + lcd.printf("%d",i); + wait(0.05); + ledV = 0; + ledY = 1; + wait(0.05); + j=j++; + } + lcd.cls(); + lcd.locate(0, 0); + lcd.printf("How do you find"); + lcd.locate(0, 1); + lcd.printf("it ??? Go out !"); + i = 0; + while(i < 80){ + ledV = 0; + ledY = 1; + wait(0.05); + ledY = 0; + ledV = 1; + wait(0.05); + if(menuL == 1 && menuR == 1){ + i = i++; + } + } + ledY = 0; + ledV = 0; lcd.cls(); //loading lcd.locate(0, 0); lcd.printf("Servomotors will"); lcd.locate(0, 1); lcd.printf("be positioned as"); - wait(3); + wait(2); lcd.locate(0, 0); lcd.printf("be positioned as"); lcd.locate(0, 1); lcd.printf("potentiometers, "); - wait(3); + wait(2); lcd.locate(0, 0); lcd.printf("potentiometers, "); lcd.locate(0, 1); lcd.printf("please wait. "); - wait(3); + wait(2); lcd.cls(); lcd.locate(4, 0); lcd.printf(": x servo"); @@ -434,23 +480,24 @@ - ledY = 0; //running - ledV = 1; - while(menuR == 0 && menuL == 0){ - servoRL = analogX.read(); - xPos = analogX.read(); - disp = xPos*100; - lcd.locate(0, 0); + i=0; + j = 20; + lcd.locate(0, 0); + while(i<j){ + float mesure = analogX.read(); + mesure = mesure*120; + disp = rand(); + xPos = mesure/100; lcd.printf("%3d", disp); - servoHL = analogY.read(); - yPos = analogY.read(); - yPos = analogY.read(); - disp = yPos*100; - lcd.locate(0, 1); - lcd.printf("%3d", disp); - wait(vitesse); + mesure = analogY.read(); + mesure = mesure*120; + disp = rand(); + yPos = mesure/100; + wait(0.5); + i = i++; } - ledV = 0; + page = 4; + ok = 1; } } } \ No newline at end of file