Robert Abad
/
Lab4_3
sinusoid wave generator with pot input
main.cpp@0:51c3fa0f0a03, 2013-10-25 (annotated)
- Committer:
- rabad1
- Date:
- Fri Oct 25 07:41:52 2013 +0000
- Revision:
- 0:51c3fa0f0a03
sinusoid wave generator with input from pot
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rabad1 | 0:51c3fa0f0a03 | 1 | #include "mbed.h" |
rabad1 | 0:51c3fa0f0a03 | 2 | |
rabad1 | 0:51c3fa0f0a03 | 3 | #define INPUT_SCALAR (0.01f) |
rabad1 | 0:51c3fa0f0a03 | 4 | |
rabad1 | 0:51c3fa0f0a03 | 5 | AnalogIn Ain(p19); |
rabad1 | 0:51c3fa0f0a03 | 6 | AnalogOut Aout(p18); |
rabad1 | 0:51c3fa0f0a03 | 7 | float i; |
rabad1 | 0:51c3fa0f0a03 | 8 | |
rabad1 | 0:51c3fa0f0a03 | 9 | int main() |
rabad1 | 0:51c3fa0f0a03 | 10 | { |
rabad1 | 0:51c3fa0f0a03 | 11 | while(1) { |
rabad1 | 0:51c3fa0f0a03 | 12 | for (i=0; i<2; i=i+0.05) { |
rabad1 | 0:51c3fa0f0a03 | 13 | Aout=0.5+0.5*sin(i*3.14159); // Compute the sine value, + half the range |
rabad1 | 0:51c3fa0f0a03 | 14 | |
rabad1 | 0:51c3fa0f0a03 | 15 | // Controls the sine wave period |
rabad1 | 0:51c3fa0f0a03 | 16 | // NOTE to my fellow students: |
rabad1 | 0:51c3fa0f0a03 | 17 | // in order to get to pot to work as an input to control the frequency, |
rabad1 | 0:51c3fa0f0a03 | 18 | // I've had to scale the setting of the pot. However, I have not had |
rabad1 | 0:51c3fa0f0a03 | 19 | // enough scope time to play with the scalar value to fully understand |
rabad1 | 0:51c3fa0f0a03 | 20 | // the how the pot affects the frequency. So I encourage you to play |
rabad1 | 0:51c3fa0f0a03 | 21 | // the scalar value to get it to work within the desired frequency range |
rabad1 | 0:51c3fa0f0a03 | 22 | wait(Ain*INPUT_SCALAR); |
rabad1 | 0:51c3fa0f0a03 | 23 | } |
rabad1 | 0:51c3fa0f0a03 | 24 | } |
rabad1 | 0:51c3fa0f0a03 | 25 | } |
rabad1 | 0:51c3fa0f0a03 | 26 |