初めての実際のプログラミング プロジェクトとして、モールス信号で Arduino を「SOS」で点滅させようとしています。
私はそうすることに成功しましたが、今はもっと効率的にコードを書きたいと思っています。これが私のバージョンです。S を 2 回点滅させるために while ループを実装するにはどうすればよいですか? これは、カウンターを使用して反復を追跡することを複雑にしているようです。
int led = 13;
//yj Integer representing dit (morse ' . ')
int dit = 500;
//yj Integer representing dah (morse ' - '>)
//yj Testing a multiple of another constant integer to make the timing scalable.
int dah = dit*3;
int blankTime = 100;
// the setup routine runs once when you press reset:
void setup() {
// initialize the digital pin as an output.
pinMode(led, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(dit); // wait
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(blankTime); // wait
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(dit); // wait
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(blankTime); // wait
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(dit); // wait
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(blankTime); // wait
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(dah); // wait
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(blankTime); // wait
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(dah); // wait
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(blankTime); // wait
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(dah); // wait
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(blankTime); // wait
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(dit); // wait
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(blankTime); // wait
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(dit); // wait
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(blankTime); // wait
digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level)
delay(dit); // wait
digitalWrite(led, LOW); // turn the LED off by making the voltage LOW
delay(blankTime); // wait
}
//TODO:
//Loop counter implementation for multiples (SOS = 3 dit, 3 dah, 3 dit.)