Rauno U
/
Miisu
Six crescent shaped legs
main.cpp@0:0b7259fdb68a, 2016-03-24 (annotated)
- Committer:
- phairero
- Date:
- Thu Mar 24 11:01:18 2016 +0000
- Revision:
- 0:0b7259fdb68a
- Child:
- 1:8b0322a353f4
This program tests the motor.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
phairero | 0:0b7259fdb68a | 1 | #include "mbed.h" |
phairero | 0:0b7259fdb68a | 2 | #include "time.h" |
phairero | 0:0b7259fdb68a | 3 | |
phairero | 0:0b7259fdb68a | 4 | Timer timer; |
phairero | 0:0b7259fdb68a | 5 | PwmOut mypwm(PB_0); |
phairero | 0:0b7259fdb68a | 6 | DigitalOut dir1(PC_0); |
phairero | 0:0b7259fdb68a | 7 | DigitalOut dir2(PC_1); |
phairero | 0:0b7259fdb68a | 8 | InterruptIn encA(PA_0); |
phairero | 0:0b7259fdb68a | 9 | InterruptIn bt(USER_BUTTON); |
phairero | 0:0b7259fdb68a | 10 | Serial pc(SERIAL_TX, SERIAL_RX); |
phairero | 0:0b7259fdb68a | 11 | |
phairero | 0:0b7259fdb68a | 12 | int iLoe = 0; |
phairero | 0:0b7259fdb68a | 13 | int isItTime = 0; |
phairero | 0:0b7259fdb68a | 14 | int iUus = 0; |
phairero | 0:0b7259fdb68a | 15 | int iAeg = 0; |
phairero | 0:0b7259fdb68a | 16 | //int iVan[2] = {0,0}; |
phairero | 0:0b7259fdb68a | 17 | double dPwm = 0.01; |
phairero | 0:0b7259fdb68a | 18 | int lastB= bt; |
phairero | 0:0b7259fdb68a | 19 | |
phairero | 0:0b7259fdb68a | 20 | void start(){ |
phairero | 0:0b7259fdb68a | 21 | iUus = timer.read_us(); |
phairero | 0:0b7259fdb68a | 22 | timer.reset(); |
phairero | 0:0b7259fdb68a | 23 | } |
phairero | 0:0b7259fdb68a | 24 | void stop(){ |
phairero | 0:0b7259fdb68a | 25 | iAeg = timer.read_us(); |
phairero | 0:0b7259fdb68a | 26 | } |
phairero | 0:0b7259fdb68a | 27 | |
phairero | 0:0b7259fdb68a | 28 | void button(){ |
phairero | 0:0b7259fdb68a | 29 | isItTime = 1; |
phairero | 0:0b7259fdb68a | 30 | } |
phairero | 0:0b7259fdb68a | 31 | |
phairero | 0:0b7259fdb68a | 32 | int main(){ |
phairero | 0:0b7259fdb68a | 33 | encA.rise(&start); |
phairero | 0:0b7259fdb68a | 34 | encA.fall(&stop); |
phairero | 0:0b7259fdb68a | 35 | bt.fall(&button); |
phairero | 0:0b7259fdb68a | 36 | timer.start(); |
phairero | 0:0b7259fdb68a | 37 | mypwm.write(dPwm); |
phairero | 0:0b7259fdb68a | 38 | //mypwm.period_ms(10); |
phairero | 0:0b7259fdb68a | 39 | //mypwm.pulsewidth_ms(4); |
phairero | 0:0b7259fdb68a | 40 | dir1 = 1; |
phairero | 0:0b7259fdb68a | 41 | dir2 = 0; |
phairero | 0:0b7259fdb68a | 42 | |
phairero | 0:0b7259fdb68a | 43 | while(1) { |
phairero | 0:0b7259fdb68a | 44 | if (isItTime){ |
phairero | 0:0b7259fdb68a | 45 | isItTime = 0; |
phairero | 0:0b7259fdb68a | 46 | dPwm = dPwm + 0.1; |
phairero | 0:0b7259fdb68a | 47 | if (dPwm>=1){ |
phairero | 0:0b7259fdb68a | 48 | dPwm--; |
phairero | 0:0b7259fdb68a | 49 | } |
phairero | 0:0b7259fdb68a | 50 | mypwm.write(dPwm); |
phairero | 0:0b7259fdb68a | 51 | } |
phairero | 0:0b7259fdb68a | 52 | else { |
phairero | 0:0b7259fdb68a | 53 | pc.printf("%f: %d/%d\n",dPwm,iUus,iAeg); |
phairero | 0:0b7259fdb68a | 54 | } |
phairero | 0:0b7259fdb68a | 55 | } |
phairero | 0:0b7259fdb68a | 56 | } |