Yaroslav Barabanov
/
turret_2017
для управления турелью
gun.cpp@0:690effcc5be0, 2017-01-15 (annotated)
- Committer:
- Yar
- Date:
- Sun Jan 15 22:16:03 2017 +0000
- Revision:
- 0:690effcc5be0
- Child:
- 3:e47c0c98f515
new program for turret
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Yar | 0:690effcc5be0 | 1 | #include "gun.hpp" |
Yar | 0:690effcc5be0 | 2 | #include "mbed.h" |
Yar | 0:690effcc5be0 | 3 | #include "rtos.h" |
Yar | 0:690effcc5be0 | 4 | #include "sounds.hpp" |
Yar | 0:690effcc5be0 | 5 | |
Yar | 0:690effcc5be0 | 6 | DigitalOut gunPin(PA_13); |
Yar | 0:690effcc5be0 | 7 | PwmOut outSignalGun(PB_3); |
Yar | 0:690effcc5be0 | 8 | |
Yar | 0:690effcc5be0 | 9 | void shotGun(void) { |
Yar | 0:690effcc5be0 | 10 | gunPin = 1; |
Yar | 0:690effcc5be0 | 11 | outSignalGun.period(1.0/1500.0); // 1500hz period |
Yar | 0:690effcc5be0 | 12 | outSignalGun = 0.5; //50% duty cycle - max volume |
Yar | 0:690effcc5be0 | 13 | Thread::wait(10); |
Yar | 0:690effcc5be0 | 14 | short tik = 0; |
Yar | 0:690effcc5be0 | 15 | char isStateGun = 1; |
Yar | 0:690effcc5be0 | 16 | for (short i = 0; i < 1500; i = i + 100) { |
Yar | 0:690effcc5be0 | 17 | outSignalGun.period(1.0/(float)(1500.0 - i)); |
Yar | 0:690effcc5be0 | 18 | outSignalGun = 0.5; |
Yar | 0:690effcc5be0 | 19 | Thread::wait(20); |
Yar | 0:690effcc5be0 | 20 | if (tik < 3) { |
Yar | 0:690effcc5be0 | 21 | tik++; |
Yar | 0:690effcc5be0 | 22 | } else { |
Yar | 0:690effcc5be0 | 23 | tik = 0; |
Yar | 0:690effcc5be0 | 24 | isStateGun ^= 1; |
Yar | 0:690effcc5be0 | 25 | gunPin = isStateGun; |
Yar | 0:690effcc5be0 | 26 | } |
Yar | 0:690effcc5be0 | 27 | } |
Yar | 0:690effcc5be0 | 28 | outSignalGun = 0.0; |
Yar | 0:690effcc5be0 | 29 | //Thread::wait(200); |
Yar | 0:690effcc5be0 | 30 | gunPin = 0; |
Yar | 0:690effcc5be0 | 31 | } |
Yar | 0:690effcc5be0 | 32 | |
Yar | 0:690effcc5be0 | 33 | void enabledGun(void) { |
Yar | 0:690effcc5be0 | 34 | gunPin = 1; |
Yar | 0:690effcc5be0 | 35 | } |
Yar | 0:690effcc5be0 | 36 | |
Yar | 0:690effcc5be0 | 37 | void disabledGun(void) { |
Yar | 0:690effcc5be0 | 38 | gunPin = 0; |
Yar | 0:690effcc5be0 | 39 | } |