友情提示:380元/半年,儿童学编程,就上码丁实验室。
使用micro:bit+gamer:bit作为输入手柄,控制屏幕上的输入法,进行打字:

说明:
①gamer:bit左侧的↑ ↓ ← →方向按钮,控制“焦点”的移动
②X按钮“确认”字母,Y按钮输出“空格”
上位机的Processing程序代码:
import processing.serial.*;
Serial myPort;
int index=0;
int val;
int d=40;
int h=70;
String str="";
void setup(){
size(680,200);
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 115200);
}
void draw(){
background(255);
fill(255,0,0);textSize(20);
text("Input: ",20,50);
fill(0);
text(str,90,50);
if(myPort.available()>0){
val = myPort.read();
print(char(val));
if(char(val)=='u'){
index-=13;if(index<0){index+=26;}
}
if(char(val)=='d'){
index+=13;index%=26;
}
if(char(val)=='l'){
index--;
if(index<0){index=25;}
}
if(char(val)=='r'){
index++;
if(index>25){index=0;}
}
if(char(val)=='x'){
fill(0);
str+=char(index+97);
}
if(char(val)=='y'){
fill(0);
str+=" ";
}
val=0;
}
for(int i=0;i<13;i++){
if(index%13==i && index<13){fill(0,255,0,100);}
else{fill(255);}
rect(20+i*50,20+h,d,d);
if(index%13==i && index>=13){fill(0,255,0,100);}
else{fill(255);}
rect(20+i*50,70+h,d,d);
fill(0);//textSize(20);
text(char(i+97),35+i*50,48+h);
text(char(i+110),35+i*50,98+h);
}
}
始发于知乎专栏:牧之