最初、私はこのウェブサイトとarduinoを初めて使っていますので、これは単なる愚かな過ちであると確信しています。arduino whileループは一度だけ実行します
私はアルドゥイノの遊び人を作ることに取り組んでいます。これは不完全なので、現在はシリアル入力を受け取り、16x2のLCD画面にアンダースコアとスペースを付けます。
私のコードは次のようになります。
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
String content = "";
int loopcount=0;
int loopend;
char character;
void setup(){
Serial.begin(9600);
lcd.begin(16, 2);
lcd.setCursor(0,1);
while(!Serial.available()){}
while(Serial.available()) {
character = Serial.read();
delay(5);
content.concat(character);
}
loopend=content.length();
while(!loopend==loopcount){
if(content.charAt(loopcount)==' '){
lcd.print(' ');
}else{
lcd.print('_');
}
loopcount++;
}
}
void loop(){
}
問題は、印刷 'または' _ 'のいずれかのwhileループが1回だけ実行されることです。エラーメッセージが表示されず、最初の文字が正常に動作します。 ありがとうございます!