mbed嵌入式编程(一):闪灯blinking,测量芯片温度
电路板:NUCLEO H743ZI2;编程环境:Arm Compiler V6.13.1
#include "mbed.h"
#include "platform/mbed_thread.h"
// Blinking rate in milliseconds
#define BLINKING_RATE_MS 500
Serial pc(USBTX, USBRX); // tx, rx
AnalogIn adc(ADC_TEMP);
AnalogIn adc1(ADC_VREF);
AnalogIn adc2(ADC_VBAT);
float tempv,temp,adcvref,vbat;
int main()
{
pc.printf("Hello World!\n\r");
DigitalOut led(LED1); //LED1
while (true) {
led = !led;
tempv = adc.read()* 3.3 ;
adcvref = adc1.read()* 3.3 ;
vbat = adc2.read()* 3.3 ;
temp = ((tempv - 0.76)/2.5) + 25;
pc.printf("temp:%.2f adc vref:%.2f vbat:%.2f\n",temp,adcvref,vbat);
thread_sleep_for(BLINKING_RATE_MS);
}
}
仅闪灯代码
#include "mbed.h"
#include "platform/mbed_thread.h"
Serial pc(USBTX, USBRX); // tx, rx
DigitalOut led(LED1); //LED1
int main()
{
pc.printf("Hello World!\n\r");
while (true) {
led = !led;
thread_sleep_for(500);
}
}
mbed os2 闪灯
#include "mbed.h"
DigitalOut myled(LED1);
int main() {
while(1) {
myled = 1;
wait(0.2);
myled = 0;
wait(0.2);
}
}
网友评论