terry LAI / Mbed 2 deprecated ESDC2014-pwm

Dependencies:   mbed

Fork of ESDC2014 by terry LAI

Committer:
terryLAI
Date:
Mon Jul 07 06:10:11 2014 +0000
Revision:
6:7ab57721c0fb
Parent:
5:098e6a44bd94
wait pwm;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
TonyYI 0:3417ca0a36c0 1 /******************************************************
TonyYI 0:3417ca0a36c0 2
TonyYI 0:3417ca0a36c0 3 ****┏┓ ┏┓
TonyYI 0:3417ca0a36c0 4 **┏┛┻━━━━━━┛┻┓
TonyYI 0:3417ca0a36c0 5 **┃ ┃
TonyYI 0:3417ca0a36c0 6 **┃ ━━━ ┃
TonyYI 0:3417ca0a36c0 7 **┃ ┳┛ ┗┳ ┃
TonyYI 0:3417ca0a36c0 8 **┃ ┃
TonyYI 0:3417ca0a36c0 9 **┃ ''' ┻ ''' ┃
TonyYI 0:3417ca0a36c0 10 **┃ ┃
TonyYI 0:3417ca0a36c0 11 **┗━━┓ ┏━━┛
TonyYI 0:3417ca0a36c0 12 *******┃ ┃
TonyYI 0:3417ca0a36c0 13 *******┃ ┃
TonyYI 0:3417ca0a36c0 14 *******┃ ┃
TonyYI 0:3417ca0a36c0 15 *******┃ ┗━━━━━━━━┓
TonyYI 0:3417ca0a36c0 16 *******┃ ┃━┓
TonyYI 0:3417ca0a36c0 17 *******┃ NO BUG ┏━┛
TonyYI 0:3417ca0a36c0 18 *******┃ ┃
TonyYI 0:3417ca0a36c0 19 *******┗━┓ ┓ ┏━┏━┓ ━┛
TonyYI 0:3417ca0a36c0 20 ***********┃ ┛ ┛ ┃ ┛ ┛
TonyYI 0:3417ca0a36c0 21 ***********┃ ┃ ┃ ┃ ┃ ┃
TonyYI 0:3417ca0a36c0 22 ***********┗━┛━┛ ┗━┛━┛
TonyYI 0:3417ca0a36c0 23
TonyYI 0:3417ca0a36c0 24 This part is added by project ESDC2014 of CUHK team.
TonyYI 0:3417ca0a36c0 25 All the code with this header are under GPL open source license.
TonyYI 0:3417ca0a36c0 26 This program is running on Mbed Platform 'mbed LPC1768' avaliable in 'http://mbed.org'.
TonyYI 0:3417ca0a36c0 27 **********************************************************/
TonyYI 0:3417ca0a36c0 28
TonyYI 0:3417ca0a36c0 29 #include "buzzer.h"
TonyYI 0:3417ca0a36c0 30
terryLAI 2:442902ec3aa1 31 extern "C" void mbed_reset();
terryLAI 2:442902ec3aa1 32
TonyYI 0:3417ca0a36c0 33 Buzzer::Buzzer(MyDigitalOut* buzzer)
TonyYI 0:3417ca0a36c0 34 {
TonyYI 0:3417ca0a36c0 35 this->_buzzer = buzzer;
terryLAI 6:7ab57721c0fb 36 boot();
TonyYI 0:3417ca0a36c0 37 }
TonyYI 0:3417ca0a36c0 38
TonyYI 0:3417ca0a36c0 39 Buzzer::~Buzzer(){}
TonyYI 0:3417ca0a36c0 40
terryLAI 1:cbec1283a16a 41 void Buzzer::ON()
TonyYI 0:3417ca0a36c0 42 {
TonyYI 0:3417ca0a36c0 43 *_buzzer = 0;
TonyYI 0:3417ca0a36c0 44 }
TonyYI 0:3417ca0a36c0 45
terryLAI 1:cbec1283a16a 46 void Buzzer::OFF()
TonyYI 0:3417ca0a36c0 47 {
TonyYI 0:3417ca0a36c0 48 *_buzzer = 1;
terryLAI 1:cbec1283a16a 49 }
terryLAI 1:cbec1283a16a 50
terryLAI 1:cbec1283a16a 51 void Buzzer::setFlag()
terryLAI 1:cbec1283a16a 52 {
terryLAI 1:cbec1283a16a 53 flag=1;
terryLAI 1:cbec1283a16a 54 }
terryLAI 1:cbec1283a16a 55
terryLAI 1:cbec1283a16a 56 void Buzzer::cleanFlag()
terryLAI 1:cbec1283a16a 57 {
terryLAI 1:cbec1283a16a 58 flag=0;
terryLAI 1:cbec1283a16a 59 }
terryLAI 1:cbec1283a16a 60
terryLAI 5:098e6a44bd94 61 void Buzzer::check_time_out()
terryLAI 5:098e6a44bd94 62 {
terryLAI 5:098e6a44bd94 63 if(flag == 1)
terryLAI 5:098e6a44bd94 64 {
terryLAI 5:098e6a44bd94 65 ON();
terryLAI 5:098e6a44bd94 66 wait(3);
terryLAI 5:098e6a44bd94 67 mbed_reset();
terryLAI 5:098e6a44bd94 68 }
terryLAI 5:098e6a44bd94 69 else
terryLAI 5:098e6a44bd94 70 {
terryLAI 5:098e6a44bd94 71 OFF();
terryLAI 5:098e6a44bd94 72 }
terryLAI 5:098e6a44bd94 73 }
terryLAI 1:cbec1283a16a 74
terryLAI 5:098e6a44bd94 75 void Buzzer::time_out_init()
terryLAI 5:098e6a44bd94 76 {
terryLAI 5:098e6a44bd94 77 setFlag();
terryLAI 5:098e6a44bd94 78 time_out.detach();
terryLAI 5:098e6a44bd94 79 time_out.attach(this, &Buzzer::check_time_out, TIME_OUT);
terryLAI 5:098e6a44bd94 80 }
terryLAI 6:7ab57721c0fb 81
terryLAI 6:7ab57721c0fb 82 void Buzzer::target_not_found()
terryLAI 6:7ab57721c0fb 83 {
terryLAI 6:7ab57721c0fb 84 ON();
terryLAI 6:7ab57721c0fb 85 wait(0.1);
terryLAI 6:7ab57721c0fb 86 OFF();
terryLAI 6:7ab57721c0fb 87 wait(0.1);
terryLAI 6:7ab57721c0fb 88 ON();
terryLAI 6:7ab57721c0fb 89 wait(0.2);
terryLAI 6:7ab57721c0fb 90 OFF();
terryLAI 6:7ab57721c0fb 91 }
terryLAI 6:7ab57721c0fb 92
terryLAI 6:7ab57721c0fb 93
terryLAI 6:7ab57721c0fb 94 void Buzzer::boot()
terryLAI 6:7ab57721c0fb 95 {
terryLAI 6:7ab57721c0fb 96 ON();
terryLAI 6:7ab57721c0fb 97 wait(0.1);
terryLAI 6:7ab57721c0fb 98 OFF();
terryLAI 6:7ab57721c0fb 99 wait(0.1);
terryLAI 6:7ab57721c0fb 100 ON();
terryLAI 6:7ab57721c0fb 101 wait(0.1);
terryLAI 6:7ab57721c0fb 102 OFF();
terryLAI 6:7ab57721c0fb 103 wait(0.1);
terryLAI 6:7ab57721c0fb 104 ON();
terryLAI 6:7ab57721c0fb 105 wait(0.2);
terryLAI 6:7ab57721c0fb 106 OFF();
terryLAI 6:7ab57721c0fb 107 }
terryLAI 6:7ab57721c0fb 108
terryLAI 6:7ab57721c0fb 109
terryLAI 6:7ab57721c0fb 110 void Buzzer::take_photo()
terryLAI 6:7ab57721c0fb 111 {
terryLAI 6:7ab57721c0fb 112 ON();
terryLAI 6:7ab57721c0fb 113 wait(0.2);
terryLAI 6:7ab57721c0fb 114 OFF();
terryLAI 6:7ab57721c0fb 115 }
terryLAI 6:7ab57721c0fb 116
terryLAI 6:7ab57721c0fb 117 void Buzzer::notice(uint8_t type)
terryLAI 6:7ab57721c0fb 118 {
terryLAI 6:7ab57721c0fb 119 switch (type)
terryLAI 6:7ab57721c0fb 120 {
terryLAI 6:7ab57721c0fb 121 case BUZZER_TARGET_NOT_FOUND:
terryLAI 6:7ab57721c0fb 122 target_not_found();
terryLAI 6:7ab57721c0fb 123 break;
terryLAI 6:7ab57721c0fb 124
terryLAI 6:7ab57721c0fb 125 case BUZZER_TAKE_PHOTO:
terryLAI 6:7ab57721c0fb 126 take_photo();
terryLAI 6:7ab57721c0fb 127 break;
terryLAI 6:7ab57721c0fb 128 }
terryLAI 6:7ab57721c0fb 129 }
terryLAI 6:7ab57721c0fb 130
terryLAI 6:7ab57721c0fb 131