2020 noshiro

Dependencies:   mbed

Committer:
sashida_h
Date:
Wed May 20 05:17:20 2020 +0000
Revision:
3:f63ebe27e4bc
Parent:
2:be979d53b674
[change]mbed os 2 Library update e95d10626187

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
sashida_h 2:be979d53b674 7 AnalogIn analog_value(PA_0);
sashida_h 2:be979d53b674 8 Serial pc(PA_9, PA_10, 9600);
bcostm 0:c8c068641d77 9
sashida_h 2:be979d53b674 10 DigitalOut red(PA_7);
sashida_h 2:be979d53b674 11 DigitalOut yellow(PB_0);
sashida_h 2:be979d53b674 12 DigitalOut blue(PB_1);
bcostm 0:c8c068641d77 13
bcostm 0:c8c068641d77 14 int main()
bcostm 0:c8c068641d77 15 {
bcostm 0:c8c068641d77 16 float meas_r;
bcostm 0:c8c068641d77 17 float meas_v;
bcostm 0:c8c068641d77 18
sashida_h 2:be979d53b674 19 pc.printf("\nAnalogIn example\n");
bcostm 0:c8c068641d77 20
bcostm 0:c8c068641d77 21 while(1) {
bcostm 0:c8c068641d77 22
bcostm 0:c8c068641d77 23 meas_r = analog_value.read(); // Read the analog input value (value from 0.0 to 1.0 = full ADC conversion range)
bcostm 0:c8c068641d77 24 meas_v = meas_r * 3300; // Converts value in the 0V-3.3V range
bcostm 0:c8c068641d77 25
bcostm 0:c8c068641d77 26 // Display values
sashida_h 2:be979d53b674 27 pc.printf("%f,%.0f\r\n", meas_r, meas_v);
bcostm 0:c8c068641d77 28
bcostm 0:c8c068641d77 29 // LED is ON is the value is below 1V
sashida_h 2:be979d53b674 30 if (meas_v > 2000) {
sashida_h 2:be979d53b674 31 red = 1; // LED ON
sashida_h 2:be979d53b674 32 yellow = 0;
sashida_h 2:be979d53b674 33 blue = 0;
sashida_h 2:be979d53b674 34 }else if(meas_v > 1200) {
sashida_h 2:be979d53b674 35 red = 1; // LED ON
sashida_h 2:be979d53b674 36 yellow = 1;
sashida_h 2:be979d53b674 37 blue = 0;
sashida_h 2:be979d53b674 38 }else{
sashida_h 2:be979d53b674 39 red = 1; // LED ON
sashida_h 2:be979d53b674 40 yellow = 1;
sashida_h 2:be979d53b674 41 blue = 1;
bcostm 0:c8c068641d77 42 }
bcostm 0:c8c068641d77 43
sashida_h 2:be979d53b674 44 wait(0.2); // 1 second
bcostm 0:c8c068641d77 45 }
bcostm 0:c8c068641d77 46 }