#include "mbed.h"
#include "math.h"
AnalogIn analog_value_01(A0);
AnalogIn analog_value_02(A1);
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut gpioDIN(PF_12);
DigitalOut gpioSCLK(PD_15);
DigitalOut gpioCS(PD_14);
void Write_MAX548x(int x)
{
int i=0;
gpioCS=0;
for(i=0;i<16;i++)
{
gpioSCLK=0;
if((x<<i)&0x8000) gpioDIN=1;
else gpioDIN=0;
gpioSCLK=1;
}
gpioCS=1;
}
int main() {
float analog_01,analog_02;
float temp1;
printf("\nAnalogIn example\n");
printf("\nA0 is Analog channel \n");
printf("\nA1 is Digital channel \n");
while(1) {
analog_01 = analog_value_01.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
analog_01 = analog_01 * 3300; // Change the value to be in the 0 to 3300 range
analog_02 = analog_value_02.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
analog_02 = analog_02 * 3300; // Change the value to be in the 0 to 3300 range
if(abs(temp1-analog_01)>5)
printf("A0 = %.0f mV\n", analog_01);
printf("A1 = %.0f mV\n", analog_02);
temp1=analog_01;
if(analog_01>825) led1 = 1;
if(analog_01>1650) led2 = 1;
if(analog_01>2475) led3 = 1;
if(analog_01<2475) led3 = 0;
if(analog_01<1650) led2 = 0;
if(analog_01<825) led1 = 0;
wait(0.2); // 200 ms
Write_MAX548x(0x0120);
}
}
|