Nucleo_Example_Demo.

Dependencies:   mbed

Committer:
makeworks
Date:
Tue Sep 26 01:21:55 2017 +0000
Revision:
5:39b5a7958d17
Parent:
4:b5ca7f122564
??README.md

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:d5bd863b2036 1 #include "mbed.h"
bcostm 0:d5bd863b2036 2
makeworks 4:b5ca7f122564 3 //------------------------------------
makeworks 4:b5ca7f122564 4 // Hyperterminal configuration
makeworks 4:b5ca7f122564 5 // 115200 bauds, 8-bit data, no parity
makeworks 4:b5ca7f122564 6 //------------------------------------
bcostm 0:d5bd863b2036 7
makeworks 4:b5ca7f122564 8 Serial pc(SERIAL_TX, SERIAL_RX, 115200);
makeworks 4:b5ca7f122564 9 DigitalOut led_red((PinName)LED_RED, (int)0);//高电平点亮,低电平熄灭
makeworks 4:b5ca7f122564 10 DigitalIn user_button((PinName)USER_BUTTON, (PinMode)PullUp);
makeworks 4:b5ca7f122564 11 AnalogIn analog_value(A0);
makeworks 4:b5ca7f122564 12 PwmOut mypwm(PWM_OUT);
makeworks 4:b5ca7f122564 13
makeworks 4:b5ca7f122564 14 Ticker read_analog_ticker;
makeworks 4:b5ca7f122564 15
makeworks 4:b5ca7f122564 16 void read_analog_value()
bcostm 0:d5bd863b2036 17 {
makeworks 4:b5ca7f122564 18 float meas = analog_value.read(); // Converts and read the analog input value (value from 0.0 to 1.0)
makeworks 4:b5ca7f122564 19 meas = meas * 3300; // Change the value to be in the 0 to 3300 range
makeworks 4:b5ca7f122564 20 pc.printf("measure = %.0f mV\r\n", meas);
makeworks 4:b5ca7f122564 21 }
makeworks 4:b5ca7f122564 22
makeworks 4:b5ca7f122564 23 int main(void)
makeworks 4:b5ca7f122564 24 {
makeworks 4:b5ca7f122564 25 pc.printf("\nAnalogIn example\r\n");
makeworks 4:b5ca7f122564 26
makeworks 4:b5ca7f122564 27 mypwm.period_ms(10);
makeworks 4:b5ca7f122564 28 mypwm.pulsewidth_ms(1);
makeworks 4:b5ca7f122564 29 printf("pwm set to %.2f %%\n", mypwm.read() * 100);
makeworks 4:b5ca7f122564 30
makeworks 4:b5ca7f122564 31 // Init the ticker with the address of the function (toggle_led) to be attached and the interval (100 ms)
makeworks 4:b5ca7f122564 32 read_analog_ticker.attach(&read_analog_value, 1);
makeworks 3:a7b520fad123 33
makeworks 3:a7b520fad123 34 while (1) {
makeworks 4:b5ca7f122564 35 if (0 == user_button) {
makeworks 4:b5ca7f122564 36 led_red.write(1);
makeworks 4:b5ca7f122564 37 } else
makeworks 4:b5ca7f122564 38 led_red.write(0);
makeworks 4:b5ca7f122564 39 wait(0.1); // 100 ms
bcostm 0:d5bd863b2036 40 }
bcostm 0:d5bd863b2036 41 }