smd.iotkit.ch
/
0-06-06-Uebung
6.6. Sobald kein magnetisches Feld mehr vorhanden, Akustisches Signal auslösen.
main.cpp@1:4df8cc0c6b73, 2019-02-01 (annotated)
- Committer:
- marcel1691
- Date:
- Fri Feb 01 10:14:53 2019 +0000
- Revision:
- 1:4df8cc0c6b73
- Parent:
- 0:76692683baea
Update mbed os 5.11
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
stefan1691 | 0:76692683baea | 1 | /** 6.6. Sobald kein magnetisches Feld mehr vorhanden, Akustisches Signal auslösen. |
stefan1691 | 0:76692683baea | 2 | */ |
stefan1691 | 0:76692683baea | 3 | #include "mbed.h" |
stefan1691 | 0:76692683baea | 4 | |
stefan1691 | 0:76692683baea | 5 | // Hall Sensor |
marcel1691 | 1:4df8cc0c6b73 | 6 | AnalogIn hallSensor( A3 ); |
stefan1691 | 0:76692683baea | 7 | // Summer (Buzzer) |
marcel1691 | 1:4df8cc0c6b73 | 8 | PwmOut speaker( D3 ); |
stefan1691 | 0:76692683baea | 9 | |
stefan1691 | 0:76692683baea | 10 | int main() |
stefan1691 | 0:76692683baea | 11 | { |
stefan1691 | 0:76692683baea | 12 | while(1) |
stefan1691 | 0:76692683baea | 13 | { |
marcel1691 | 1:4df8cc0c6b73 | 14 | if ( hallSensor.read() > 0.6f ) |
stefan1691 | 0:76692683baea | 15 | { |
stefan1691 | 0:76692683baea | 16 | // Polizei Sirene |
stefan1691 | 0:76692683baea | 17 | speaker.period( 1.0 / 969.0 ); // 969 = Tonfrequenz in Hz |
stefan1691 | 0:76692683baea | 18 | speaker = 0.5f; |
stefan1691 | 0:76692683baea | 19 | wait( 0.5f ); |
stefan1691 | 0:76692683baea | 20 | speaker.period( 1.0 / 800.0 ); |
stefan1691 | 0:76692683baea | 21 | wait( 0.5f ); |
stefan1691 | 0:76692683baea | 22 | } |
stefan1691 | 0:76692683baea | 23 | else |
stefan1691 | 0:76692683baea | 24 | speaker = 0.0f; |
stefan1691 | 0:76692683baea | 25 | } |
stefan1691 | 0:76692683baea | 26 | } |