2020 noshiro

Dependencies:   mbed

Committer:
sashida_h
Date:
Tue May 19 22:18:01 2020 +0000
Revision:
1:352debc405fd
Parent:
0:c8c068641d77
Child:
2:be979d53b674
initial commit 2020 noshiro

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sashida_h 1:352debc405fd 1 /*
sashida_h 1:352debc405fd 2 initial 2020/05/20
sashida_h 1:352debc405fd 3 */
sashida_h 1:352debc405fd 4
bcostm 0:c8c068641d77 5 #include "mbed.h"
bcostm 0:c8c068641d77 6
bcostm 0:c8c068641d77 7 AnalogIn analog_value(A0);
bcostm 0:c8c068641d77 8
bcostm 0:c8c068641d77 9 DigitalOut led(LED1);
bcostm 0:c8c068641d77 10
bcostm 0:c8c068641d77 11 int main()
bcostm 0:c8c068641d77 12 {
bcostm 0:c8c068641d77 13 float meas_r;
bcostm 0:c8c068641d77 14 float meas_v;
bcostm 0:c8c068641d77 15
bcostm 0:c8c068641d77 16 printf("\nAnalogIn example\n");
bcostm 0:c8c068641d77 17
bcostm 0:c8c068641d77 18 while(1) {
bcostm 0:c8c068641d77 19
bcostm 0:c8c068641d77 20 meas_r = analog_value.read(); // Read the analog input value (value from 0.0 to 1.0 = full ADC conversion range)
bcostm 0:c8c068641d77 21 meas_v = meas_r * 3300; // Converts value in the 0V-3.3V range
bcostm 0:c8c068641d77 22
bcostm 0:c8c068641d77 23 // Display values
bcostm 0:c8c068641d77 24 printf("measure = %f = %.0f mV\n", meas_r, meas_v);
bcostm 0:c8c068641d77 25
bcostm 0:c8c068641d77 26 // LED is ON is the value is below 1V
bcostm 0:c8c068641d77 27 if (meas_v < 1000) {
bcostm 0:c8c068641d77 28 led = 1; // LED ON
bcostm 0:c8c068641d77 29 } else {
bcostm 0:c8c068641d77 30 led = 0; // LED OFF
bcostm 0:c8c068641d77 31 }
bcostm 0:c8c068641d77 32
bcostm 0:c8c068641d77 33 wait(1.0); // 1 second
bcostm 0:c8c068641d77 34 }
bcostm 0:c8c068641d77 35 }