使用操縱桿控制滑鼠游標。使用 LCD 從溫度傳感器讀取溫度。通過運行到 2 個單執行緒。
/*
* Copyright (c) 2006-2020 Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*/
#include "mbed.h"
#include "USBMouse.h"
#include "LM75B.h"
#include "C12832.h"
Thread thread;
Thread thread1;
//Thread thread2;
//Thread thread3;
//Thread thread4;
USBMouse mouse;
// x and y axis of the joystick
AnalogIn ainx(A0);
AnalogIn ainy(A1);
BusIn*input = new BusIn(p15,p12,p13,p16);
int16_t x;
int16_t y;
C12832 lcd(p5, p7, p6, p8, p11);
LM75B sensor(p28,p27);
Serial pc(USBTX,USBRX);
void MouseCursor() {
while (1){int state = input->read(); // get current state from input
x = 0;
y = 0;
switch(state & input->mask()) { //mask bits to test
case 0x0:
// do nothing - stick neutral position
break;
case 0x1:
// stick down (relative to LCD screen)
y = -1;
break;
case 0x2:
// stick up
y = 1;
break;
case 0x4:
// stick left
x = -1;
break;
case 0x8:
// stick right
x = 1;
}
// moves mouse to specified x, y coordinates on screen
mouse.move(x, y);
wait_us(500);
}
}
void TemperatureSensor(){
//Try to open the LM75B
if (sensor.open()) {
printf("Device detected!\n");
while (1) {
lcd.cls();
lcd.locate(0,3);
lcd.printf("Temp = %.3f\n", (float)sensor);
wait(1.0);
}
} else {
error("Device not detected!\n");
}
}
int main() {
thread.start(MouseCursor);
thread1.start(TemperatureSensor);
}
錯誤資訊是:錯誤:“main.cpp”中的未知型別名稱“Serial”,行:27,列:1
這些是相關鏈接:https : //os.mbed.com/docs/mbed-os/v6.15/apis/usbmouse.html、https : //os.mbed.com/docs/mbed-os/v6。 15/program-setup/concepts.html, https://os.mbed.com/cookbook/mbed-application-board#11-lm75b-temperature-sensor。
uj5u.com熱心網友回復:
從MBED Online Compiler匯出專案時,將mbed_config.hmbed 生成的檔案添加到device.h目標 MCU的檔案中,如下所示。:
將以下宣告添加到device.h目標 MCU的檔案中:
#include "mbed_config.h"
以下是 MBED Online Compiler 輸出中相關檔案的目錄結構:
output_folder
|
|------ "mbed_config.h"
|
|------ mbed/
|
|------ {TARGET-PlATFORM}/
|
|------ {TOOLCHAIN}/
|
|------ "device.h"
uj5u.com熱心網友回復:
洗掉該行:
Serial pc(USBTX,USBRX);
變數pc不在任何地方使用,對的參考Serial是多余的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/386263.html
