![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
main.cpp@0:12678c3187de, 2011-10-31 (annotated)
- Committer:
- gbeardall
- Date:
- Mon Oct 31 17:36:23 2011 +0000
- Revision:
- 0:12678c3187de
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gbeardall | 0:12678c3187de | 1 | /* |
gbeardall | 0:12678c3187de | 2 | * wave2 |
gbeardall | 0:12678c3187de | 3 | * |
gbeardall | 0:12678c3187de | 4 | */ |
gbeardall | 0:12678c3187de | 5 | |
gbeardall | 0:12678c3187de | 6 | #include "mbed.h" |
gbeardall | 0:12678c3187de | 7 | |
gbeardall | 0:12678c3187de | 8 | DigitalOut myled(LED1); |
gbeardall | 0:12678c3187de | 9 | AnalogOut ano1(p18); |
gbeardall | 0:12678c3187de | 10 | |
gbeardall | 0:12678c3187de | 11 | Ticker oscTick1; |
gbeardall | 0:12678c3187de | 12 | |
gbeardall | 0:12678c3187de | 13 | float oscData[] = |
gbeardall | 0:12678c3187de | 14 | // { 0,1,0,1,0,1 }; |
gbeardall | 0:12678c3187de | 15 | // { 0, .5 }; |
gbeardall | 0:12678c3187de | 16 | // { .33,.67,.33,.67,.33,.67 }; |
gbeardall | 0:12678c3187de | 17 | // { 0, .15, .05, .1 }; // 1:1 |
gbeardall | 0:12678c3187de | 18 | { 0, .15, 0, .15, .05, .1, .05, .1, }; |
gbeardall | 0:12678c3187de | 19 | // { |
gbeardall | 0:12678c3187de | 20 | // 0, .15, 0, .15, 0, .15, 0, .15, 0, .15, 0, .15, // 0, .15, 0, .15, 0, .15, 0, .15, 0, .15, 0, .15, |
gbeardall | 0:12678c3187de | 21 | // .05, .1, .05, .1, .05, .1, .05, .1, .05, .1, .05, .1, // .05, .1, .05, .1, .05, .1, .05, .1, .05, .1, .05, .1, |
gbeardall | 0:12678c3187de | 22 | // }; |
gbeardall | 0:12678c3187de | 23 | |
gbeardall | 0:12678c3187de | 24 | const int dx_max = sizeof(oscData)/sizeof(oscData[0]); |
gbeardall | 0:12678c3187de | 25 | int dx = 0; |
gbeardall | 0:12678c3187de | 26 | |
gbeardall | 0:12678c3187de | 27 | // --------------------------------------------------------------------------- |
gbeardall | 0:12678c3187de | 28 | |
gbeardall | 0:12678c3187de | 29 | void oscOut1() { |
gbeardall | 0:12678c3187de | 30 | // uint16_t v = (oscData[dx++]*0xFFFF)/3; |
gbeardall | 0:12678c3187de | 31 | float v = oscData[dx++]; |
gbeardall | 0:12678c3187de | 32 | // ano1.write_u16(v); |
gbeardall | 0:12678c3187de | 33 | ano1 = v; |
gbeardall | 0:12678c3187de | 34 | if(dx >= dx_max) dx = 0; |
gbeardall | 0:12678c3187de | 35 | } |
gbeardall | 0:12678c3187de | 36 | |
gbeardall | 0:12678c3187de | 37 | // --------------------------------------------------------------------------- |
gbeardall | 0:12678c3187de | 38 | |
gbeardall | 0:12678c3187de | 39 | int main() { |
gbeardall | 0:12678c3187de | 40 | |
gbeardall | 0:12678c3187de | 41 | ano1 = 0; |
gbeardall | 0:12678c3187de | 42 | oscTick1.attach_us(&oscOut1, 500); // chip period: 500-1KHz, 417-1200Hz, 833-600Hz |
gbeardall | 0:12678c3187de | 43 | |
gbeardall | 0:12678c3187de | 44 | while(1) { |
gbeardall | 0:12678c3187de | 45 | myled = 1; |
gbeardall | 0:12678c3187de | 46 | wait(0.2); |
gbeardall | 0:12678c3187de | 47 | myled = 0; |
gbeardall | 0:12678c3187de | 48 | wait(0.2); |
gbeardall | 0:12678c3187de | 49 | } |
gbeardall | 0:12678c3187de | 50 | |
gbeardall | 0:12678c3187de | 51 | } // main |
gbeardall | 0:12678c3187de | 52 |