Demonstrates AnalogOut with a wave taken from an array of data, as well as an AnalogIn pass-through.

Dependencies:   mbed

main.cpp

Committer:
rossatmsoe
Date:
2018-10-22
Revision:
1:12830e864576
Parent:
0:41657a1f55b7

File content as of revision 1:12830e864576:

#include "mbed.h"

/*  This program creates two analog outputs:
    A staircase wave on A2
    Voltage representing light level on D13

    It is assumed that the photoresistor is connected to A0
    in the usual manner.
*/

AnalogIn light(A0);

// Our board only has two analog outputs, on A2 and D13.
AnalogOut my_output1(A2);
AnalogOut my_output2(D13);

// Levels for the staircase wave.
float wave_data[]= {0,.25,.5,.75,1,.75,.5,.25};

int length=8;

int main()  {
    
    while(1) {

        // Go through the array to output the voltage levels.
        // Also pass the light level out to D13 (my_output2).
        // Change the level every 1 ms.

        for(int k=0; k<length; k++) {
            my_output1 = wave_data[k];
            my_output2=light;
            wait_ms(1);
        }
    }
}