Modified code for 2 servo motors

Dependencies:   DebounceIn mbed

Files at this revision

API Documentation at this revision

Comitter:
goodguy8791
Date:
Wed Oct 18 16:01:04 2017 +0000
Commit message:
Modified code for 2 servo motors

Changed in this revision

DebounceIn.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DebounceIn.lib	Wed Oct 18 16:01:04 2017 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/users/AjK/code/DebounceIn/#31ae5cfb44a4
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Oct 18 16:01:04 2017 +0000
@@ -0,0 +1,88 @@
+#include "mbed.h"
+//#include "wave_player.h"
+//#include "SDFileSystem.h"
+#include "DebounceIn.h"
+
+PwmOut myservo(p21);
+DebounceIn pb1(p20);
+PwmOut myservo1(p22);
+DebounceIn pb2(p19);
+//DigitalIn pb1 (p20);
+//AnalogIn linpot(p20);
+//Serial pc(USBTX, USBRX);
+//DigitalOut myled(LED1);
+//SDFileSystem sd(p5, p6, p7, p8, "sd"); //SD card
+//AnalogOut DACout(p26);
+//wave_player waver(&DACout);
+
+void moveServoIn()
+{
+    while((pb1 && pb2) == 1)
+        //myled = 1;
+        // rotate 90 degrees one way
+        for(int i=3; i<=7; i++) {
+            myservo = i/100.0;
+            myservo1 = i/100.0;
+            wait(0.01);
+        }
+}
+
+void moveServoOut()
+{
+    while((pb1 && pb2) == 1)
+        //myled = 0;
+        for(int i=7; i>3; i--) {
+            myservo = i/100.0;
+            myservo1 = i/100.0;
+            wait(0.01);
+        }
+}
+
+/*void playSound()
+{
+    FILE *wave_file;
+    wave_file=fopen("/sd/police_siren.wav","r");
+    waver.play(wave_file);
+    fclose(wave_file);
+}*/
+
+int main()
+{
+    //pc.printf("begin\n");
+
+    // button up: state = 0, button halfway: state = 1; button down: state = 2
+    int state = 2;
+
+    // pull up the pushbutton to prevent bouncing
+    pb1.mode(PullUp);
+    wait(.001);
+
+    // servo begins at 30 degrees
+    for(int i=0; i<=3; i++) {
+        myservo = i/100.0;
+        wait(0.01);
+    }
+
+    while(1) {
+        // Servo code
+        if ((pb1 && pb2) == 1 && state == 2) {
+            moveServoIn();
+            state = 1;
+        }
+        // rotate 90 degrees other way
+        if ((pb1 && pb2) == 1 && state == 1) {
+            moveServoOut();
+            state = 2;
+        }
+
+        // SD card code
+
+        // speaker code
+
+        // read linear potentiometer
+        //if (linpot < 0.5) {
+        //float potval = linpot;
+        //pc.printf("linear pot: %f\n", potval);
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Oct 18 16:01:04 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed/builds/b484a57bc302
\ No newline at end of file