KL25Z firmware. Responsible for activating the servo based on input from the nRF51822.

Dependencies:   Servo mbed

Fork of HW5_Servo by StepSense

Committer:
adarsh5723
Date:
Mon Nov 10 03:55:53 2014 +0000
Revision:
1:19dd18051447
Parent:
0:9898eeeb7143
Child:
2:13e9c2f5ca10
Part of Homework 5.; Firmware for controlling the servo.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sunitav 0:9898eeeb7143 1 // Hello World to sweep a servo through its full range
sunitav 0:9898eeeb7143 2
sunitav 0:9898eeeb7143 3 #include "mbed.h"
sunitav 0:9898eeeb7143 4 #include "Servo.h"
sunitav 0:9898eeeb7143 5
adarsh5723 1:19dd18051447 6
adarsh5723 1:19dd18051447 7
adarsh5723 1:19dd18051447 8 DigitalIn toggleSwitch(D3);
adarsh5723 1:19dd18051447 9 AnalogIn ldr0(A5);
adarsh5723 1:19dd18051447 10 PwmOut servoDriver(D2);
sunitav 0:9898eeeb7143 11 Servo myservo(D2); //change digital pin here
adarsh5723 1:19dd18051447 12
sunitav 0:9898eeeb7143 13 #define THRESHOLD .001
sunitav 0:9898eeeb7143 14 int counter = 0;
sunitav 0:9898eeeb7143 15
adarsh5723 1:19dd18051447 16 Serial pc(USBTX, USBRX);
sunitav 0:9898eeeb7143 17 int main() {
adarsh5723 1:19dd18051447 18 //myservo.position(270.0f);
adarsh5723 1:19dd18051447 19 myservo.calibrate(.0006, 120.0);
adarsh5723 1:19dd18051447 20 bool servoLogic = 0;
adarsh5723 1:19dd18051447 21
sunitav 0:9898eeeb7143 22 while(1){
adarsh5723 1:19dd18051447 23
adarsh5723 1:19dd18051447 24
adarsh5723 1:19dd18051447 25 #if 1
adarsh5723 1:19dd18051447 26 if (toggleSwitch == 1)
adarsh5723 1:19dd18051447 27 //if (ldr0.read() > 0.7)
adarsh5723 1:19dd18051447 28 servoLogic = 1;
adarsh5723 1:19dd18051447 29 else
adarsh5723 1:19dd18051447 30 servoLogic = 0;
sunitav 0:9898eeeb7143 31 //recieve_data(ServoLogic);
adarsh5723 1:19dd18051447 32 if (servoLogic)
sunitav 0:9898eeeb7143 33 {
adarsh5723 1:19dd18051447 34 float o = 0.0;
sunitav 0:9898eeeb7143 35 myservo = o;
sunitav 0:9898eeeb7143 36 }
sunitav 0:9898eeeb7143 37 else{
adarsh5723 1:19dd18051447 38 float f= 1;
sunitav 0:9898eeeb7143 39 myservo = f;
sunitav 0:9898eeeb7143 40 }
adarsh5723 1:19dd18051447 41 printf("%f\n\r",ldr0.read());
adarsh5723 1:19dd18051447 42 #else
adarsh5723 1:19dd18051447 43 #if 0
adarsh5723 1:19dd18051447 44 int pos = 0;
adarsh5723 1:19dd18051447 45 for(pos = 0; pos < 100; pos += 1) // goes from 0 degrees to 180 degrees
adarsh5723 1:19dd18051447 46 { // in steps of 1 degree
adarsh5723 1:19dd18051447 47 myservo = pos/100; // tell servo to go to position in variable 'pos'
adarsh5723 1:19dd18051447 48 wait(0.015); // waits 15ms for the servo to reach the position
adarsh5723 1:19dd18051447 49 }
adarsh5723 1:19dd18051447 50 for(pos = 100; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
adarsh5723 1:19dd18051447 51 {
adarsh5723 1:19dd18051447 52 myservo = pos/100; // tell servo to go to position in variable 'pos'
adarsh5723 1:19dd18051447 53 wait(0.015); // waits 15ms for the servo to reach the position
adarsh5723 1:19dd18051447 54 }
adarsh5723 1:19dd18051447 55 #else
adarsh5723 1:19dd18051447 56 myservo = 2;
adarsh5723 1:19dd18051447 57 #endif
adarsh5723 1:19dd18051447 58 #endif
sunitav 0:9898eeeb7143 59 wait(.2);
sunitav 0:9898eeeb7143 60 }
sunitav 0:9898eeeb7143 61 }