servo_hello_world

Dependencies:   mbed Servo MMA7660

liam.cpp

Committer:
mistaherd
Date:
2021-02-23
Revision:
0:1891c8e1bb4a

File content as of revision 0:1891c8e1bb4a:

#include "mbed.h"
#include "Servo.h"
#include <iostream>
#include "MMA7660.h"

Serial pc(USBTX, USBRX); // tx, rx


DigitalIn joy_up(p15);
DigitalIn joy_down(p12);

Servo myservo1(p21);
Servo myservo2(p22);


AnalogIn p1(p19);
AnalogIn p2(p20);

MMA7660 MMA(p28, p27);
DigitalOut connectionLed(LED1);//Accel OK LED

int main (){
     char option;
     pc.printf("command list 1,2,3,4,5,6,7\n");
    while(1){
                            
              option = pc.getc();
              
              if (MMA.testConnection())
              {
                connectionLed = 1 ; //Accelerometer init OK
                }
               if(option =='1')
               {
                   myservo1 = 1 ;
                   myservo2 = 1 ;
                   }
            else if(option == '2')
            {
                   myservo1 = - 0.5 ;
                   myservo2 = - 0.5 ;
                   }
            else if(option =='3')
            {
                myservo1 = 0;
                myservo2 = 0;
            }
            else if (option =='4')
            {
                float x ;
                cout << "please enter in the degree you want the servo to be at go (limit is 180 degrees  be sure to hit enter after  command \n\r" ;
                cin >> x;    // waits for the user to type something and hit enter to finsh
                wait(0.01);
                myservo1 = x/180;
                myservo2 = x/180 ;
                
            }
            else if (option == '5')
            {
                float x=0 ,y=0;
                x = (x + MMA.x() );
                y = (y -(MMA.y() ));
                  myservo1 = x;
                  myservo2 =y ;
                  //pc.printf("mma.x is = %f ,mma.y is = %f \n \r",MMA.x() ,MMA.y()); use this to see vaules the servo uses
                  
            }
            else if (option == '6')
            {
                if (joy_up)
                {
                   
                    myservo1= myservo1+ 0.1;
                    myservo2 = myservo2 + 0.1;
                     wait(0.1);    
                }
                else if(joy_down)
                {
                    myservo1= myservo1- 0.1;
                    myservo2 = myservo2 - 0.1;
                     wait(0.1);    
                }
            }
            else if (option == '7')
            {
                 myservo1=p1;
                 myservo2=p2; 
                
            }
            }
            }