MicroMouse

Dependencies:   QEI mbed

Committer:
nathanielchu
Date:
Thu Oct 22 23:50:09 2015 +0000
Revision:
0:524c6a42541a
Child:
1:92eb1c9934ee
commit 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nathanielchu 0:524c6a42541a 1 #include "mbed.h"
nathanielchu 0:524c6a42541a 2 #include "PinDefinitions.h"
nathanielchu 0:524c6a42541a 3
nathanielchu 0:524c6a42541a 4 Serial pc(USBTX, USBRX);
nathanielchu 0:524c6a42541a 5 InterruptIn mybutton(USER_BUTTON);
nathanielchu 0:524c6a42541a 6 DigitalOut LD3(LD3);
nathanielchu 0:524c6a42541a 7 DigitalOut motor_enabler(PB_6);
nathanielchu 0:524c6a42541a 8
nathanielchu 0:524c6a42541a 9 int distance = LENC.getPulses();
nathanielchu 0:524c6a42541a 10
nathanielchu 0:524c6a42541a 11
nathanielchu 0:524c6a42541a 12 void setLeftPwm(float speed) {
nathanielchu 0:524c6a42541a 13 if (speed == 0) {
nathanielchu 0:524c6a42541a 14 LMOTORA = 1.0;
nathanielchu 0:524c6a42541a 15 LMOTORB = 1.0;
nathanielchu 0:524c6a42541a 16 }
nathanielchu 0:524c6a42541a 17
nathanielchu 0:524c6a42541a 18 if (speed > 0) {
nathanielchu 0:524c6a42541a 19 LMOTORA = speed;
nathanielchu 0:524c6a42541a 20 LMOTORB = 0;
nathanielchu 0:524c6a42541a 21 }
nathanielchu 0:524c6a42541a 22 else {
nathanielchu 0:524c6a42541a 23 LMOTORA = 0;
nathanielchu 0:524c6a42541a 24 LMOTORB = -speed;
nathanielchu 0:524c6a42541a 25 }
nathanielchu 0:524c6a42541a 26 }
nathanielchu 0:524c6a42541a 27
nathanielchu 0:524c6a42541a 28 void setRightPwm(float speed) {
nathanielchu 0:524c6a42541a 29 if (speed == 0) {
nathanielchu 0:524c6a42541a 30 RMOTORA = 1.0;
nathanielchu 0:524c6a42541a 31 RMOTORB = 1.0;
nathanielchu 0:524c6a42541a 32 }
nathanielchu 0:524c6a42541a 33
nathanielchu 0:524c6a42541a 34 if (speed > 0) {
nathanielchu 0:524c6a42541a 35 RMOTORA = speed;
nathanielchu 0:524c6a42541a 36 RMOTORB = 0;
nathanielchu 0:524c6a42541a 37 }
nathanielchu 0:524c6a42541a 38 else {
nathanielchu 0:524c6a42541a 39 RMOTORA = 0;
nathanielchu 0:524c6a42541a 40 RMOTORB = -speed;
nathanielchu 0:524c6a42541a 41 }
nathanielchu 0:524c6a42541a 42 }
nathanielchu 0:524c6a42541a 43
nathanielchu 0:524c6a42541a 44 void pressed()
nathanielchu 0:524c6a42541a 45 {
nathanielchu 0:524c6a42541a 46 //led1 = !led1;
nathanielchu 0:524c6a42541a 47 pc.printf("Hellooooo\r\n");
nathanielchu 0:524c6a42541a 48 }
nathanielchu 0:524c6a42541a 49
nathanielchu 0:524c6a42541a 50 int main() {
nathanielchu 0:524c6a42541a 51
nathanielchu 0:524c6a42541a 52 //mybutton.fall(&pressed);
nathanielchu 0:524c6a42541a 53 LD3 = 0;
nathanielchu 0:524c6a42541a 54
nathanielchu 0:524c6a42541a 55 motor_enabler = 1;
nathanielchu 0:524c6a42541a 56 while(1){
nathanielchu 0:524c6a42541a 57
nathanielchu 0:524c6a42541a 58 RMOTORA = 1.0;
nathanielchu 0:524c6a42541a 59 RMOTORB = 0;
nathanielchu 0:524c6a42541a 60 LMOTORA = 1.0;
nathanielchu 0:524c6a42541a 61 LMOTORB = 0;
nathanielchu 0:524c6a42541a 62
nathanielchu 0:524c6a42541a 63 }
nathanielchu 0:524c6a42541a 64
nathanielchu 0:524c6a42541a 65 }
nathanielchu 0:524c6a42541a 66 /*
nathanielchu 0:524c6a42541a 67 while (LENC.getPulses() < 5000) {
nathanielchu 0:524c6a42541a 68 led1 = 1;
nathanielchu 0:524c6a42541a 69 setLeftPwm(0.5);
nathanielchu 0:524c6a42541a 70 }
nathanielchu 0:524c6a42541a 71 LENC.reset();
nathanielchu 0:524c6a42541a 72 while (LENC.getPulses() < 5000) {
nathanielchu 0:524c6a42541a 73 led1 = 0;
nathanielchu 0:524c6a42541a 74 setLeftPwm(0.25);
nathanielchu 0:524c6a42541a 75 }
nathanielchu 0:524c6a42541a 76 LENC.reset();
nathanielchu 0:524c6a42541a 77 while (LENC.getPulses() < 10000) {
nathanielchu 0:524c6a42541a 78 led1 = 1;
nathanielchu 0:524c6a42541a 79 setLeftPwm(1.0);
nathanielchu 0:524c6a42541a 80 }
nathanielchu 0:524c6a42541a 81 */
nathanielchu 0:524c6a42541a 82
nathanielchu 0:524c6a42541a 83
nathanielchu 0:524c6a42541a 84
nathanielchu 0:524c6a42541a 85
nathanielchu 0:524c6a42541a 86