KL26Z带有USB接口,可以做USB设备。我们先试试USB键盘吧,还是利用Mbed,几分钟就可以做出一个USB键盘。按下K3,输出“Hello World from Mbed”;按下K4,输出字母s。可以先打开记事本,在按下K3或K4,就可以在记事本上看到输出了。#include "mbed.h"
#include "USBKeyboard.h"
DigitalIn Key1(PTD6);
DigitalIn Key2(PTA4);
uint8_t cnt = 0;
//USBKeyboard
USBKeyboard keyboard;
int main(void) {
while (1) {
if(Key1 == 0)
{
keyboard.printf("Hello World from Mbed\r\n");
}
if(Key2 == 0)
{
keyboard.keyCode('s', 0);
}
wait(0.1);
}
}
|