Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 1:19dd18051447, committed 2014-11-10
- Comitter:
- adarsh5723
- Date:
- Mon Nov 10 03:55:53 2014 +0000
- Parent:
- 0:9898eeeb7143
- Commit message:
- Part of Homework 5.; Firmware for controlling the servo.
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Fri Nov 07 04:08:42 2014 +0000
+++ b/main.cpp Mon Nov 10 03:55:53 2014 +0000
@@ -3,43 +3,59 @@
#include "mbed.h"
#include "Servo.h"
+
+
+DigitalIn toggleSwitch(D3);
+AnalogIn ldr0(A5);
+PwmOut servoDriver(D2);
Servo myservo(D2); //change digital pin here
-bool ServoLogic=true;
-AnalogIn pin0(A0);
-AnalogIn pin1(A1);
-AnalogIn pin2(A2);
-AnalogIn pin3(A3);
-float photoresistors[4];
+
#define THRESHOLD .001
int counter = 0;
+Serial pc(USBTX, USBRX);
int main() {
- myservo.calibrate(.0006, 75.0);
+ //myservo.position(270.0f);
+ myservo.calibrate(.0006, 120.0);
+ bool servoLogic = 0;
+
while(1){
+
+
+ #if 1
+ if (toggleSwitch == 1)
+ //if (ldr0.read() > 0.7)
+ servoLogic = 1;
+ else
+ servoLogic = 0;
//recieve_data(ServoLogic);
- if (ServoLogic)
+ if (servoLogic)
{
- float o = .1;
+ float o = 0.0;
myservo = o;
}
else{
- float f= 0.28;
+ float f= 1;
myservo = f;
}
-
- photoresistors[0] = pin0.read();
- photoresistors[1] = pin1.read();
- photoresistors[2] = pin2.read();
- photoresistors[3] = pin3.read();
-
- for(int p=0; p<3; p += 1)
- {
- if ((photoresistors[p]) < THRESHOLD)
- counter=counter++;
- //
- }
-
- //send_data(counter)
+ printf("%f\n\r",ldr0.read());
+ #else
+#if 0
+ int pos = 0;
+ for(pos = 0; pos < 100; pos += 1) // goes from 0 degrees to 180 degrees
+ { // in steps of 1 degree
+ myservo = pos/100; // tell servo to go to position in variable 'pos'
+ wait(0.015); // waits 15ms for the servo to reach the position
+ }
+ for(pos = 100; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
+ {
+ myservo = pos/100; // tell servo to go to position in variable 'pos'
+ wait(0.015); // waits 15ms for the servo to reach the position
+ }
+#else
+ myservo = 2;
+#endif
+#endif
wait(.2);
}
}