0
0

ArduinoUnoR4WiFi: シリアル通信 (受信)

Posted at

仕様

'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);
}

// ---------------------------------------------------------------------
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0