Kazuhiro Hirasawa
/
STM32_180SENSOR_ADC4_RS_Ver2_CommCLD
WathchDog
main.cpp
- Committer:
- orain3
- Date:
- 2019-02-23
- Revision:
- 2:d69d10b670c5
- Parent:
- 1:c896654c679b
- Child:
- 3:b082ed02d08c
File content as of revision 2:d69d10b670c5:
#include "mbed.h" Serial pc(SERIAL_TX,SERIAL_RX); Serial modem(D1,D0); AnalogIn adc_1(A0); AnalogIn adc_2(A1); AnalogIn adc_3(A2); AnalogIn adc_4(A3); DigitalOut led(LED1); DigitalOut sokutei(D3); DigitalOut commndout(D4); DigitalIn in1(D9,PullNone); DigitalIn in2(D10,PullNone); DigitalIn kansyutu(D6,PullNone); DigitalIn commandin(D7,PullNone); DigitalIn jmp(D2,PullUp); int main() { float sum1,sum2,sum3,sum4; float ad1,ad2,ad3,ad4; float temp,turb,s; int i,cnt; modem.baud(38400); modem.format(8,Serial::None,1); pc.printf("\nSTM32 ADC internal channels reading example\r\n"); temp = 0; turb = 0; s = 0; sokutei = 1; while(1) { if (jmp) sokutei = 1; else sokutei = 0; sum1 = 0; sum2 = 0; sum3 = 0; sum4 = 0; cnt = 0; for (i=0;i<10;i++) { sum1 += adc_1.read(); sum2 += adc_2.read(); sum3 += adc_3.read(); sum4 += adc_4.read(); cnt += 1; wait(0.001); // if (modem.readable()) { // pc.printf("%c\r",modem.getc()); // wait(0.01); // modem.printf("=04,PVAL,%01.04f,0,\r",temp); // } } if(cnt != 0) { ad1 = sum1/cnt; ad2 = sum2/cnt; ad3 = sum3/cnt; ad4 = sum4/cnt; } else { ad1 = adc_1.read(); ad2 = adc_2.read(); ad3 = adc_3.read(); ad4 = adc_4.read(); } pc.printf("ADC = %f %f %f %f \r\n", ad1,ad2,ad3,ad4); temp = ad1*66-30+0.3; turb = 2.1*((ad2-0.166)/0.6642*1000+25.5); s = 0; } }