Dependencies: Servo TextLCD mbed
main.cpp
- Committer:
- clementb
- Date:
- 2016-06-16
- Revision:
- 2:2728901fd798
- Parent:
- 1:c3a33d9372f5
- Child:
- 3:dd4efdfbbf01
File content as of revision 2:2728901fd798:
/* 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); - 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 int vitesse = 0.05; //------------------a------------- CHANGE IT TO REDUCE/INCREASE SERVOMOTORS SPEED ---------------------------- int page; int i = 0; int xPos = 0; int yPos = 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; servoHL = 0; while(i != 50){ ledY = 1; ledV = 0; wait(0.05); ledY = 0; ledV = 1; wait(0.05); i = i++; } ledY = 0; ledV = 0; while(1) { ledY = 1; lcd.cls(); lcd.locate(0,0); lcd.printf("Reset servo pos"); wait(2); lcd.locate(0, 1); lcd.printf("Please wait..."); wait(3); lcd.cls(); lcd.locate(3, 0); lcd.printf(" : x servo"); lcd.locate(3, 1); lcd.printf(" : y servo"); lcd.locate(0,0); lcd.printf("%3d", xPos); lcd.locate(0, 1); lcd.printf("%3d", yPos); if(xPos !=0){ while(yPos != 120){ yPos = yPos + 1; lcd.locate(0, 1); lcd.printf("%3d", yPos); servoHL = yPos; wait(vitesse); } } while(xPos != 0){ xPos = xPos - 0.01; lcd.locate(0,0); lcd.printf("%3d", xPos); servoRL = xPos; wait(vitesse); } while(yPos !=0){ yPos = yPos - 1; lcd.locate(0, 1); lcd.printf("%3d", yPos); servoHL = yPos; wait(vitesse); } servoRL = 0; servoHL = 0; wait(1); lcd.cls(); lcd.locate(0,0); lcd.printf("The program will"); lcd.locate(0, 1); lcd.printf("read the button"); wait(2); lcd.cls(); lcd.locate(0,0); lcd.printf("read the button"); lcd.locate(0, 1); lcd.printf("states. When"); wait(2); lcd.cls(); lcd.locate(0,0); lcd.printf("states. When"); lcd.locate(0, 1); lcd.printf("the light turn"); wait(2); lcd.cls(); lcd.locate(0,0); lcd.printf("the light turn"); lcd.locate(0, 1); lcd.printf("green, press a"); wait(2); lcd.cls(); lcd.locate(0, 0); lcd.printf("green, press a"); lcd.locate(0, 1); lcd.printf("button to change"); wait(2); lcd.cls(); lcd.locate(0, 0); lcd.printf("button to change"); lcd.locate(0, 1); lcd.printf("the programm,"); wait(2); lcd.cls(); lcd.locate(0, 0); lcd.printf("the programm,"); lcd.locate(0, 1); lcd.printf("from 1 to 5."); wait(2); ledV = 1; ledY = 0; lcd.cls(); lcd.locate(0,0); lcd.printf("Reading states.."); lcd.locate(0, 1); lcd.printf("Currentrly : P%d ", page); wait(5); if(menuR == 1) { page = page++; } else if(menuL == 1){ page = page--; } if(page >5){ page = 1; } else if(page<1){ page = 5; } ledV = 0; ledY = 1; lcd.locate(0, 1); lcd.printf("OK ! Next : P%d ", page); wait(3); /*------------------------------------------- P4 : down > up --------------------------------------------------------------*/ if(page == 4) { ledY = 1; lcd.cls(); lcd.locate(0,0); lcd.printf("Loading P4... "); lcd.locate(0,1); lcd.printf("P4 : down > up "); servoHL = 0; i = 0; wait(3); lcd.locate(3, 1); lcd.printf(": y servo "); while(i !=50){ lcd.locate(0, 1); xPos = xPos++; servoRL = xPos; lcd.printf("%3d", xPos); i = i++; wait(vitesse); } wait(1); ledY = 0; lcd.cls(); lcd.locate(0,0); lcd.printf("Running P4... "); lcd.locate(0, 1); lcd.printf(" 0 degrees"); i = 0; ledV = 1; wait(2); lcd.locate(0,1); while(i!=100){ i = i+1; lcd.locate(0,1); lcd.printf("%3d",i); servoHL = i; wait(vitesse); } yPos = 100; wait(3); ledV = 0; } /*---------------------------------------------------- P3 : righ > left -----------------------------------------------------------------*/ else if(page == 3) { ledY = 1; lcd.cls(); lcd.locate(0,0); lcd.printf("Loading P3... "); lcd.locate(0,1); lcd.printf("P3: right > left"); i = 0; wait(3); lcd.locate(3, 1); lcd.printf(": y servo "); while(i !=120){ lcd.locate(0, 1); yPos = yPos++; servoHL = yPos; lcd.printf("%3d", yPos); i = i++; wait(vitesse); } i = 0; wait(1); lcd.locate(5, 1); lcd.printf("x"); while(i !=100){ lcd.locate(0, 1); xPos = xPos++; servoRL = xPos; lcd.printf("%3d", xPos); i = i++; wait(vitesse); } i = 100; wait(1); lcd.locate(5, 1); lcd.printf("y"); while(i != 0){ lcd.locate(0, 1); yPos = yPos--; servoHL = yPos; lcd.printf("%3d", yPos); i = i--; wait(vitesse); } wait(1); ledY = 0; lcd.cls(); lcd.locate(0,0); lcd.printf("Running P3... "); lcd.locate(0, 1); lcd.printf("100 degrees"); ledV = 1; wait(2); i = 100; while(i!=0){ i = i-1; lcd.locate(0,1); lcd.printf("%3d",i); servoRL = i; wait(vitesse); } xPos = 0; wait(3); ledV = 0; } /*---------------------------------------------------- P2 : up > down ----------------------------------------------------------------*/ else if(page == 2) { //home screen ledY = 1; lcd.cls(); lcd.locate(0,0); lcd.printf("Loading P2..."); lcd.locate(0,1); lcd.printf("P2 : up > down "); wait(3); i = 0; //loading lcd.locate(3, 1); lcd.printf(": y servo "); while(i != 120){ lcd.locate(0, 1); yPos = yPos++; servoHL = yPos; lcd.printf("%3d", yPos); i = i++; wait(vitesse); } i = 0; wait(1); lcd.locate(5, 1); lcd.printf("x"); while(i != 50){ lcd.locate(0, 1); xPos = xPos++; servoRL = xPos; lcd.printf("%3d", xPos); i = i++; wait(vitesse); } i = 120; wait(1); lcd.locate(5, 1); lcd.printf("y"); while(i!= 100){ lcd.locate(0, 1); yPos = yPos--; servoHL = yPos; lcd.printf("%3d", yPos); i = i--; wait(vitesse); } wait(1); ledY = 0; //running lcd.cls(); lcd.locate(0,0); lcd.printf("Running P2... "); lcd.locate(0, 1); lcd.printf("100 : y degrees"); ledV = 1; wait(2); i = 100; while(i!=0){ i = i-1; lcd.locate(0,1); lcd.printf("%3d", i); servoHL = i; wait(vitesse); } yPos = 0; wait(3); ledV = 0; } /*---------------------------------------------- P1 : left > righ ------------------------------------------------------------------*/ else if(page == 1) { //home screen ledY = 1; lcd.cls(); lcd.locate(0,0); lcd.printf("Loading P1... "); lcd.locate(0,1); lcd.printf("P1: left > right"); wait(2); 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(2); i = 0; while(i!=100){ i = i+1; lcd.locate(0, 1); lcd.printf("%3d", i); servoRL = i; wait(vitesse); } xPos = 100; wait(3); 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(3); lcd.cls(); //loading lcd.locate(0, 0); lcd.printf("Servomotors will"); lcd.locate(0, 1); lcd.printf("be as "); wait(3); lcd.locate(0, 0); lcd.printf("be as "); lcd.locate(0, 1); lcd.printf("potentiometers, "); wait(3); lcd.locate(0, 0); lcd.printf("potentiometers, "); lcd.locate(0, 1); lcd.printf("please wait. "); wait(3); lcd.cls(); lcd.locate(4, 0); lcd.printf(": x servo"); lcd.locate(4, 1); lcd.printf(": y servo"); float mesure = analogX.read(); mesure = mesure*100; mesure = 1.2*mesure; xPos = (int) mesure; int i =0; while(xPos != i){ lcd.locate(0, 0); lcd.printf("%3d", i); i = i++; servoRL = i; wait(vitesse); } mesure = analogY.read(); mesure = mesure*100; mesure = 1.2*mesure; yPos = (int) mesure; i =0; while(i != yPos){ lcd.locate(0, 1); lcd.printf("%3d", i); i = i++; servoHL = i; wait(vitesse); } wait(1); ledY = 0; //running ledV = 1; while(menuR == 0 && menuL == 0){ float mesure = analogX.read(); mesure = mesure*100; mesure = 1.2*mesure; xPos = (int) mesure; lcd.locate(0,0); lcd.printf("%3d", xPos); servoRL = xPos; mesure = analogY.read(); mesure = mesure*100; mesure = 1.2*mesure; yPos = (int) mesure; lcd.locate(0,1); lcd.printf("%3d", yPos); servoHL = yPos; wait(vitesse); } ledV = 0; } } }