This program sets the position of the motor by taking input from switches

Dependencies:   Servo mbed

main.cpp

Committer:
EduRemo
Date:
2016-02-05
Revision:
0:9c4154e40f94

File content as of revision 0:9c4154e40f94:

// Hello World to sweep a servo through its full range

#include "mbed.h"
#include "Servo.h"

Servo myservo(PTC1);

DigitalIn sw0(PTD1);  // Switch selected as input
DigitalIn sw1(PTD3);
DigitalIn sw2(PTD2);
DigitalIn sw3(PTD0);

int main() 
{   
    while(1) 
    {
          if (sw0==0 && sw1==1 && sw2==1 && sw3==1)
          {
              myservo = 99/100.0;
              wait(0.5);
          }
          else if (sw0==1 && sw1==0 && sw2==1 && sw3==1)
          {
              myservo = 66/100.0;
              wait(0.5);
          }
          else if (sw0==1 && sw1==1 && sw2==0 && sw3==1)
          {
              myservo = 33/100.0;
              wait(0.5);
          }
          else if (sw0==1 && sw1==1 && sw2==1 && sw3==0)
          {
              myservo = 1/100.0;
              wait(0.5);
          }
          else
          {
              myservo = 50/100.0;
              wait(0.5);
          }
      }
}