
This is a program for a DIY robotic arm for demonstrates the capacities of the BIXI Bluetooth module
Dependencies: Servo TextLCD mbed
main.cpp
- Committer:
- clementb
- Date:
- 2016-06-21
- Revision:
- 6:f9179fb52bbc
- Parent:
- 5:da214688a308
File content as of revision 6:f9179fb52bbc:
/* Program created in June, 2016 by Clément BALLOT This program is for a robotic arm for demonstrates the Bixi capacities, with 2 axes. The Bixi is a Bluetooth module for touch-free control Bluetooth devices, like a smartphone or a tablet. It is develloped by Bluemint Labs. To make this project, you need : - a STM32 Nucleo board (ST). BE CAREFUL : CHOISE THE RIGH BOARD BEFORE COMPILING !!! ; - 2x servomotors (5V) ; - 2x LEDs : 1x red, 1x green ; - 3 pushbuttons ; - 4x 10K potentiometers ; - a 2 rows 16 columns alphanumeric LCD screen ; - a USB A to micro cable ; - a breadboard ; - 2x 100K resistors . */ #include "mbed.h" #include "TextLCD.h" #include "Servo.h" TextLCD lcd(D2, D3, D4, D5, D6, D7); enum LCDType{LCD16x2B}; Servo servoRL(D10); //Righ-left servo : x axe Servo servoHL(D9); //Up-down servo : y axe DigitalIn menuL(D11); //"Back" button DigitalIn menuR(D12); //"Next" button DigitalOut ledY(D8); //"Please wait" LED DigitalOut ledV(D13); //"In progress" and "press a button" LED 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 -------------------- int page; int i = 0; int disp = 0; float xPos = 0.00; float yPos = 0.00; int ok = 0; int main(){ page = 1; lcd.cls(); lcd.locate(0,0); lcd.printf("BIXI Rob'Arm :by"); lcd.locate(0,1); lcd.printf("Clement BALLOT"); servoRL = 0.00; servoHL = 0.00; while(i != 5){ ledY = 1; ledV = 0; wait(0.5); ledY = 0; ledV = 1; wait(0.5); i = i++; } ledY = 0; ledV = 0; while(1) { ledY = 1; lcd.cls(); lcd.locate(0,0); lcd.printf("Reset servo pos"); wait(1); lcd.locate(0, 1); lcd.printf("Please wait..."); wait(1); lcd.cls(); lcd.locate(3, 0); lcd.printf(" : x servo"); lcd.locate(3, 1); lcd.printf(" : y servo"); lcd.locate(0,0); disp = xPos*100; lcd.printf("%3d", disp); lcd.locate(0, 1); disp = yPos*100; lcd.printf("%3d", disp); if(xPos!=0.00){ while(yPos < 1.00){ yPos = yPos + 0.01; lcd.locate(0, 1); disp = yPos*100; lcd.printf("%3d", disp); servoHL = yPos; wait(vitesse*10); } } while(xPos > 0.00){ xPos = xPos - 0.01; lcd.locate(0,0); disp = xPos*100; lcd.printf("%3d", disp); servoRL = xPos; wait(vitesse*10); } while(yPos >0.00){ yPos = yPos - 0.01; lcd.locate(0, 1); disp = yPos*100; lcd.printf("%3d", disp); servoHL = yPos; wait(vitesse*10); } servoRL = 0.00; servoHL = 0.00; ledV = 1; ledY = 0; lcd.cls(); lcd.locate(0,0); lcd.printf("Press a button.."); lcd.locate(0, 1); lcd.printf("Currently : P%d ", page); i = 0; while(i!=20){ wait(0.1); ledV = 0; wait(0.1); ledV = 1; i = i++; } if(menuR == 1 && menuL == 1 && ok == 0){ page = 5; } 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(1); ledV = 0; ledY = 1; lcd.cls(); lcd.locate(0, 0); lcd.printf("Loading P%d...", page); lcd.locate(0, 1); lcd.printf("P%d :",page); lcd.locate(4, 1); /*------------------------------------------- P4 : down > up --------------------------------------------------------------*/ if(page == 4) { lcd.printf("down > up "); servoHL = 0; i = 0; wait(2); lcd.locate(3, 1); lcd.printf(": x servo "); while(xPos<0.50){ lcd.locate(0, 1); xPos = xPos+0.01; disp = xPos*100; servoRL = xPos; lcd.printf("%3d", disp); wait(vitesse*10); } wait(1); ledY = 0; lcd.cls(); lcd.locate(0,0); lcd.printf("Running P4... "); lcd.locate(0, 1); lcd.printf(" 0 : y servo"); ledV = 1; wait(1); lcd.locate(0,1); while(yPos<1.00){ lcd.locate(0,1); yPos = yPos + 0.01; disp = yPos*100; lcd.printf("%3d", disp); servoHL = yPos; wait(vitesse); } wait(1); ledV = 0; } /*---------------------------------------------------- P3 : left > right -----------------------------------------------------------------*/ else if(page == 3) { lcd.printf("left > right"); wait(2); lcd.locate(3, 1); lcd.printf(": y servo "); while(yPos<1.00){ yPos = yPos+0.01; servoHL = yPos; disp = yPos*100; lcd.locate(0, 1); lcd.printf("%3d", disp); wait(vitesse*10); } i = 0; wait(1); lcd.locate(5, 1); lcd.printf("x"); while(xPos<1.00){ xPos = xPos+0.01; servoRL = xPos; disp = xPos*100; lcd.locate(0, 1); lcd.printf("%3d", disp); wait(vitesse*10); } i = 100; wait(0.5); lcd.locate(5, 1); lcd.printf("y"); while(yPos>0.00){ yPos = yPos-0.01; servoHL = yPos; disp = yPos*100; lcd.locate(0, 1); lcd.printf("%3d", disp); wait(vitesse*10); } wait(1); ledY = 0; lcd.cls(); lcd.locate(0,0); lcd.printf("Running P3... "); lcd.locate(0, 1); lcd.printf("100 : x servo"); ledV = 1; wait(1); i = 100; while(xPos>0){ xPos = xPos-0.01; disp = xPos*100; servoRL = xPos; lcd.locate(0,1); lcd.printf("%3d",disp); wait(vitesse); } wait(1); ledV = 0; } /*---------------------------------------------------- P2 : up > down ----------------------------------------------------------------*/ else if(page == 2) { lcd.printf("up > down "); wait(1); i = 0; //loading lcd.locate(3, 1); lcd.printf(": y servo "); while(yPos<1.00){ yPos = yPos+0.01; servoHL = yPos; disp = yPos*100; lcd.locate(0, 1); lcd.printf("%3d", disp); wait(vitesse*10); }; lcd.locate(5, 1); lcd.printf("x"); while(xPos<0.50){ xPos = xPos+0.01; servoRL = xPos; disp = xPos*100; lcd.locate(0, 1); lcd.printf("%3d", disp); wait(vitesse*10); } lcd.locate(5, 1); lcd.printf("y"); while(yPos >0.61){ yPos = yPos-0.01; servoHL = yPos; disp = yPos*100; lcd.locate(0, 1); lcd.printf("%3d", disp); wait(vitesse*10); } wait(1); ledY = 0; //running lcd.cls(); lcd.locate(0,0); lcd.printf("Running P2... "); lcd.locate(0, 1); lcd.printf(" 60: y degrees"); ledV = 1; wait(1); yPos = 0.60; while(yPos>0.00){ disp = yPos*100; lcd.locate(0,1); lcd.printf("%3d", disp); yPos = yPos-0.01; servoHL = yPos; wait(vitesse); } yPos = 0.00; ok = 0.50; xPos = 0.00; wait(3); ledV = 0; } /*---------------------------------------------- P1 : righ > left ------------------------------------------------------------------*/ else if(page == 1){ lcd.printf("right > left"); wait(1); ledY = 0; //running lcd.cls(); lcd.locate(0,0); lcd.printf("Running P1... "); lcd.locate(0, 1); lcd.printf(" 0 : x degrees"); ledV = 1; wait(0.5); xPos = 0.00; while(xPos<1.00){ xPos = xPos+0.01; servoRL = xPos; disp = xPos*100; lcd.locate(0, 1); lcd.printf("%3d", disp); wait(vitesse); } wait(0.5); ledV = 0; } /*------------------------------------------------ P5 : manual mode ----------------------------------------------------------------*/ if(page == 5){ //home screen ledY = 1; lcd.cls(); lcd.locate(0, 0); lcd.printf("P5 : manual mode"); lcd.locate(0,1); lcd.printf("Button : exit"); wait(2); 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++; } while(i < 80){ lcd.cls(); disp = rand(); lcd.locate(0, 0); lcd.printf("How do you find"); lcd.locate(0, 1); lcd.printf("it ??? Go out !"); i = 0; 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(2); lcd.locate(0, 0); lcd.printf("be positioned as"); lcd.locate(0, 1); lcd.printf("potentiometers, "); wait(2); lcd.locate(0, 0); lcd.printf("potentiometers, "); lcd.locate(0, 1); lcd.printf("please wait. "); wait(2); lcd.cls(); lcd.locate(4, 0); lcd.printf(": x servo"); lcd.locate(4, 1); lcd.printf(": y servo"); float mesure = analogX.read(); xPos = (int) mesure*100; xPos = xPos/100; if(xPos>mesure){ while(xPos>mesure){ xPos = xPos-0.01; servoRL = xPos; disp = xPos*100; lcd.locate(0, 0); lcd.printf("%3d", disp); wait(vitesse*10); } } if(xPos<mesure){ while(xPos<mesure){ xPos = xPos+0.01; servoRL = xPos; disp = xPos*100; lcd.locate(0, 0); lcd.printf("%3d", disp); wait(vitesse*10); } } mesure = analogY.read(); yPos = (int) mesure*100; yPos = yPos/100; while(yPos!=mesure){ if(yPos>mesure){ yPos = yPos-0.01; servoHL = yPos; disp = yPos*100; lcd.locate(0, 1); lcd.printf("%3d", disp); wait(vitesse*10); } else if(yPos<mesure){ yPos = yPos+0.01; servoHL = yPos; disp = yPos*100; lcd.locate(0, 1); lcd.printf("%3d", disp); wait(vitesse); } } wait(1); i=0; j = 20; lcd.locate(0, 0); servoRL = 0.99; servoHL = 0.99; while(i<j){ float mesure = analogX.read(); mesure = mesure*120; disp = rand(); xPos = mesure/100; lcd.printf("%3d", disp); mesure = analogY.read(); mesure = mesure*120; disp = rand(); yPos = mesure/100; wait(0.5); i = i++; } page = 4; ok = 1; servoRL = 0.00; servoHL = 0.00; } } }