Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp@0:6b8f5f5410f0, 2018-10-03 (annotated)
- Committer:
- joedro
- Date:
- Wed Oct 03 14:44:10 2018 +0000
- Revision:
- 0:6b8f5f5410f0
Voice output via D/A
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| joedro | 0:6b8f5f5410f0 | 1 | #include "stimme.h" |
| joedro | 0:6b8f5f5410f0 | 2 | #include "mbed.h" |
| joedro | 0:6b8f5f5410f0 | 3 | |
| joedro | 0:6b8f5f5410f0 | 4 | Ticker tick ; // Creates periodic interrupt |
| joedro | 0:6b8f5f5410f0 | 5 | Ticker adcTick ; // Creates periodic interrupt |
| joedro | 0:6b8f5f5410f0 | 6 | AnalogOut ao(PA_4) ; // Analog output |
| joedro | 0:6b8f5f5410f0 | 7 | |
| joedro | 0:6b8f5f5410f0 | 8 | float berechnet = 0.0f; |
| joedro | 0:6b8f5f5410f0 | 9 | |
| joedro | 0:6b8f5f5410f0 | 10 | volatile int index1 = 0 ; // verachtfachen der Anzahl |
| joedro | 0:6b8f5f5410f0 | 11 | volatile int index2 = 0 ; // index into array of sin values |
| joedro | 0:6b8f5f5410f0 | 12 | |
| joedro | 0:6b8f5f5410f0 | 13 | void writeAout() |
| joedro | 0:6b8f5f5410f0 | 14 | { |
| joedro | 0:6b8f5f5410f0 | 15 | berechnet = (0.003921568627f * Text[0xb405 + index2]); // berechnet = (Frequenz[index] * 1.0f/255.0f; |
| joedro | 0:6b8f5f5410f0 | 16 | ao.write(berechnet); |
| joedro | 0:6b8f5f5410f0 | 17 | index1++; |
| joedro | 0:6b8f5f5410f0 | 18 | if(index1 > 7) |
| joedro | 0:6b8f5f5410f0 | 19 | { |
| joedro | 0:6b8f5f5410f0 | 20 | index2++; // nach 8 Takten das nächste Byte holen |
| joedro | 0:6b8f5f5410f0 | 21 | if (index2 > 0x0ae6) index2 = 0; |
| joedro | 0:6b8f5f5410f0 | 22 | index1 = 0; |
| joedro | 0:6b8f5f5410f0 | 23 | } |
| joedro | 0:6b8f5f5410f0 | 24 | } |
| joedro | 0:6b8f5f5410f0 | 25 | |
| joedro | 0:6b8f5f5410f0 | 26 | int main() |
| joedro | 0:6b8f5f5410f0 | 27 | { |
| joedro | 0:6b8f5f5410f0 | 28 | |
| joedro | 0:6b8f5f5410f0 | 29 | int old_update_us; |
| joedro | 0:6b8f5f5410f0 | 30 | int update_us; |
| joedro | 0:6b8f5f5410f0 | 31 | tick.attach_us(callback(&writeAout), update_us); // setup ticker to write to AnalogOut |
| joedro | 0:6b8f5f5410f0 | 32 | old_update_us = update_us; |
| joedro | 0:6b8f5f5410f0 | 33 | |
| joedro | 0:6b8f5f5410f0 | 34 | while (true) |
| joedro | 0:6b8f5f5410f0 | 35 | { |
| joedro | 0:6b8f5f5410f0 | 36 | if (update_us != old_update_us) |
| joedro | 0:6b8f5f5410f0 | 37 | { |
| joedro | 0:6b8f5f5410f0 | 38 | tick.attach_us(callback(&writeAout), update_us); // setup ticker to write to AnalogOut |
| joedro | 0:6b8f5f5410f0 | 39 | old_update_us = update_us; |
| joedro | 0:6b8f5f5410f0 | 40 | } |
| joedro | 0:6b8f5f5410f0 | 41 | Thread::wait(200); //in ms |
| joedro | 0:6b8f5f5410f0 | 42 | } |
| joedro | 0:6b8f5f5410f0 | 43 | } |