Demonstrates AnalogOut with a wave taken from an array of data, as well as an AnalogIn pass-through.
Dependencies: mbed
main.cpp@0:41657a1f55b7, 2017-10-24 (annotated)
- Committer:
- rossatmsoe
- Date:
- Tue Oct 24 20:46:48 2017 +0000
- Revision:
- 0:41657a1f55b7
Demonstrates AnalogOut with a wave taken from an array of data, as well as an AnalogIn pass-through.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
rossatmsoe | 0:41657a1f55b7 | 1 | #include "mbed.h" |
rossatmsoe | 0:41657a1f55b7 | 2 | |
rossatmsoe | 0:41657a1f55b7 | 3 | /* This program creates two analog outputs: |
rossatmsoe | 0:41657a1f55b7 | 4 | A staircase wave on A2 |
rossatmsoe | 0:41657a1f55b7 | 5 | Voltage representing light level on D13 |
rossatmsoe | 0:41657a1f55b7 | 6 | |
rossatmsoe | 0:41657a1f55b7 | 7 | It is assumed that the photoresistor is connected to A0 |
rossatmsoe | 0:41657a1f55b7 | 8 | in the usual manner. |
rossatmsoe | 0:41657a1f55b7 | 9 | */ |
rossatmsoe | 0:41657a1f55b7 | 10 | |
rossatmsoe | 0:41657a1f55b7 | 11 | AnalogIn light(A0); |
rossatmsoe | 0:41657a1f55b7 | 12 | |
rossatmsoe | 0:41657a1f55b7 | 13 | // Our board only has two analog outputs, on A2 and D13. |
rossatmsoe | 0:41657a1f55b7 | 14 | AnalogOut my_output1(A2); |
rossatmsoe | 0:41657a1f55b7 | 15 | AnalogOut my_output2(D13); |
rossatmsoe | 0:41657a1f55b7 | 16 | |
rossatmsoe | 0:41657a1f55b7 | 17 | // Levels for the staircase wave. |
rossatmsoe | 0:41657a1f55b7 | 18 | float wave_data[]= {0,.25,.5,.75,1,.75,.5,.25}; |
rossatmsoe | 0:41657a1f55b7 | 19 | |
rossatmsoe | 0:41657a1f55b7 | 20 | int length=8; |
rossatmsoe | 0:41657a1f55b7 | 21 | |
rossatmsoe | 0:41657a1f55b7 | 22 | int main() { |
rossatmsoe | 0:41657a1f55b7 | 23 | |
rossatmsoe | 0:41657a1f55b7 | 24 | while(1) { |
rossatmsoe | 0:41657a1f55b7 | 25 | |
rossatmsoe | 0:41657a1f55b7 | 26 | // Go through the array to output the voltage levels. |
rossatmsoe | 0:41657a1f55b7 | 27 | // Also pass the light level out to D13 (my_output2). |
rossatmsoe | 0:41657a1f55b7 | 28 | // Change the level every 1 ms. |
rossatmsoe | 0:41657a1f55b7 | 29 | |
rossatmsoe | 0:41657a1f55b7 | 30 | for(int k=0; k<length; k++) { |
rossatmsoe | 0:41657a1f55b7 | 31 | my_output1 = wave_data[k]; |
rossatmsoe | 0:41657a1f55b7 | 32 | my_output2=light; |
rossatmsoe | 0:41657a1f55b7 | 33 | wait_ms(1); |
rossatmsoe | 0:41657a1f55b7 | 34 | } |
rossatmsoe | 0:41657a1f55b7 | 35 | } |
rossatmsoe | 0:41657a1f55b7 | 36 | } |