jongrock chun / Mbed 2 deprecated For_test_code

Dependencies:   mbed

Fork of AnalogIn_HelloWorld_WIZwiki-W7500 by IOP

main.cpp

Committer:
jaynjei
Date:
2018-10-23
Revision:
9:21193ec77fbf
Parent:
8:bc6291805741

File content as of revision 9:21193ec77fbf:

/* Analog Input Example Program */

#include "mbed.h"

AnalogIn mic(A0);
PwmOut aout(D3);
InterruptIn trigger_i(D15);
PwmOut trigger_o(D14);
//PwmOut test(D5);
DigitalOut toggle1 (D0);
DigitalOut toggle2 (D1);

#define MAX_BUF_SIZE 128
//char buf0[MAX_BUF_SIZE];
char buf1[MAX_BUF_SIZE];
char buf0[MAX_BUF_SIZE];
int i = 0;
char buf_sel = 1;
int n;
float out;

void adcTickfunc() 
{
    if(buf_sel==1){
        for(i=0;i<128;i++){
            buf0[i] = mic.read_u16() >> 4;
            i++;
            toggle1 = !toggle1;
            printf("input progress... \n\r");

            if (i==MAX_BUF_SIZE){
                buf_sel = 0;
                i=0;
                printf("end \n\r");
                toggle1 = 0;
                }
            }
    }
    
    else if(buf_sel==0){
        for(i=0;i<128;i++){
            aout.write((float)buf0[i]/256*1.32);
            i++;
            printf("output progress... \n\r");
            if (i==MAX_BUF_SIZE){
                buf_sel = 1;
                i=0;
                printf("end \n\r");
                toggle2 = !toggle2;
                }
        }
    }
}
/*
    if (buf_sel) aout.write((float)buf1[i]/256);
    else         aout.write((float)buf0[i]/256);
    i++;
    
    //if (i == MAX_BUF_SIZE) i = MAX_BUF_SIZE - 1;

if (buf_sel == 0) buf0[i] = mic.read_u16() >> 4;
    else          buf1[i] = mic.read_u16() >> 4;
    i++;
    
    if (i == MAX_BUF_SIZE) { 
        i = 0;
        //toggle = !toggle;
        if (buf_sel) buf_sel = 0; else buf_sel = 1;
    }*/


int main() 
{
    printf("Hello!\n\r");
    printf("Start the communication \n\r");
    trigger_i.rise(&adcTickfunc);

    while (1) {
        trigger_o.period_us(100);
        trigger_o.write(0.5);
        //aout.period_us(50);
        //test.period(10);
        //test.write(50);
        }
}