Anton Boyt
/
Nucleo_read_analog_value_with_smooth
Read an analog value using ADC.
main.cpp@1:9685565fd3cc, 2014-12-30 (annotated)
- Committer:
- margadon
- Date:
- Tue Dec 30 11:26:34 2014 +0000
- Revision:
- 1:9685565fd3cc
- Parent:
- 0:c2d1ad5059da
smooth function
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
bcostm | 0:c2d1ad5059da | 1 | #include "mbed.h" |
margadon | 1:9685565fd3cc | 2 | #include "smooth.cpp" |
margadon | 1:9685565fd3cc | 3 | AnalogIn analog_value(PA_0); |
margadon | 1:9685565fd3cc | 4 | Serial pc(PA_11, PA_12);/* Serial6 tx rx */ |
bcostm | 0:c2d1ad5059da | 5 | DigitalOut myled(LED1); |
bcostm | 0:c2d1ad5059da | 6 | |
bcostm | 0:c2d1ad5059da | 7 | // Calculate the corresponding acquisition measure for a given value in mV |
bcostm | 0:c2d1ad5059da | 8 | #define MV(x) ((0xFFF*x)/3300) |
margadon | 1:9685565fd3cc | 9 | |
margadon | 1:9685565fd3cc | 10 | uint16_t pre_val; |
bcostm | 0:c2d1ad5059da | 11 | |
bcostm | 0:c2d1ad5059da | 12 | int main() { |
margadon | 1:9685565fd3cc | 13 | while(1) { |
margadon | 1:9685565fd3cc | 14 | //pc.printf("POPIZDOVALI\r\n"); |
bcostm | 0:c2d1ad5059da | 15 | uint16_t meas = analog_value.read_u16(); // Converts and read the analog input value |
bcostm | 0:c2d1ad5059da | 16 | if (meas > MV(1000)) { // If the value is greater than 1000 mV toggle the LED |
bcostm | 0:c2d1ad5059da | 17 | myled = !myled; |
bcostm | 0:c2d1ad5059da | 18 | } |
margadon | 1:9685565fd3cc | 19 | wait(0.8); // 200 mssdfg |
margadon | 1:9685565fd3cc | 20 | //char c = pc.getc(); |
margadon | 1:9685565fd3cc | 21 | //if(c!='q') |
margadon | 1:9685565fd3cc | 22 | uint16_t val = 2;//meas/16; |
margadon | 1:9685565fd3cc | 23 | uint16_t pre_val = 3;//meas/16; |
margadon | 1:9685565fd3cc | 24 | //smooth(&val,&pre_val,3,5); |
margadon | 1:9685565fd3cc | 25 | int ert = &val; |
margadon | 1:9685565fd3cc | 26 | int ert2 = &pre_val; |
margadon | 1:9685565fd3cc | 27 | |
margadon | 1:9685565fd3cc | 28 | smooth(ert,ert2,3,5); |
margadon | 1:9685565fd3cc | 29 | |
margadon | 1:9685565fd3cc | 30 | pc.printf("value %f - %d\r\n",meas/0xFFFF*3.30000,meas/16); |
bcostm | 0:c2d1ad5059da | 31 | } |
margadon | 1:9685565fd3cc | 32 | } |