仕様
'n' を受信したら、PD8 を ON
'f' を受信したら、PD8 を OFF
プログラム
serial_read.ino
// ---------------------------------------------------------------------
/*
serial_read.ino
May/17/2024
*/
// ---------------------------------------------------------------------
#define LED_A 8
// ---------------------------------------------------------------------
void setup() {
Serial.begin(19200);
pinMode(LED_A,OUTPUT);
for (int it=0; it<3; it++)
{
Serial.println("Hello");
delay(500);
Serial.println("Welcome");
delay(500);
}
}
// ---------------------------------------------------------------------
void loop() {
char key;
if ( Serial.available() ) {
key = Serial.read();
if (key == 'n')
{
Serial.println("PD8 ON");
digitalWrite(LED_A,HIGH);
}
else if (key == 'f')
{
Serial.println("PD8 OFF");
digitalWrite(LED_A,LOW);
}
else
{
Serial.println(key);
}
}
delay(200);
}
// ---------------------------------------------------------------------