ELCT 302 / Mbed 2 deprecated elct302_lab4_code

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
benjaminstone
Date:
Mon Mar 15 20:48:45 2021 +0000
Parent:
4:d03c2ad36d44
Commit message:
code with driving team additions

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Mar 08 18:43:41 2021 +0000
+++ b/main.cpp	Mon Mar 15 20:48:45 2021 +0000
@@ -1,6 +1,9 @@
 #include "mbed.h"
 #include <iostream>
 
+//state button
+AnalogIn input(PTC1);
+
 // localization sensor inputs
 AnalogIn sen_left(PTB0);
 AnalogIn sen_right(PTC2);
@@ -10,12 +13,21 @@
 // pwm output to servo
 PwmOut output(PTB3);
 
+//PWM output for motors
+PwmOut motorOutput(PTE21);
+//break control
+DigitalOut rightBreak(PTE0);
+DigitalOut leftBreak(PTE1);
+//motor speeds
+double speed1 = .4;
+double speed2 = .7;
+double speed3 = 1;
+
 // LED binary display for localization
 DigitalOut led_out0(D0); // 2^0 place
 DigitalOut led_out1(D1); // 2^1 place
 DigitalOut led_out2(D2); // 2^2 place
 DigitalOut led_out3(PTC7); // 2^3 place
-
 // LED displays for state control
 DigitalOut led_wait(LED3);
 DigitalOut led_run(LED2);
@@ -128,7 +140,24 @@
         i++; 
     }
 } 
-
+//motor speed update code
+void mtorUpdate(float N)
+{
+    motorOutput.period(0.00005f);  // 20 kHz control signal
+    motorOutput.write(N);    //DC of the wave
+}
+void breakUpdate(int X){
+    if(X == 1, X == 0)
+    {
+        rightBreak.write(X);
+        leftBreak.write(X);      
+    }
+}
+void changeState(float userState){
+    if(userSate <= .2){
+        //change state
+    }
+}
 int main() {
     // Steering init
     output.period(0.02f); // 50 Hz control signal