再利用Pin13內建的LED燈,在通訊視窗上的傳出訊號欄打上”A”時亮燈3秒,
並顯示”LED ON”回傳,找出ArduBlock拼圖塊↓
void
setup()
{
Serial.begin(9600);
Serial.begin(9600);
pinMode( 13 , OUTPUT);
}
void
loop()
{
if (( ( Serial.read() ) == ('A') ))
{
Serial.print( "LED ON" );
Serial.println();
digitalWrite( 13 , HIGH );
delay( 3000 );
digitalWrite( 13 , LOW );
}
}
程式先判斷是否有文字輸入,再判斷若是輸入”1”時亮燈ON,
若是輸入”0”時熄燈OFF,如都不是則顯示”ERROR”↓
char _ABVAR_1_temp = ' ' ;
void setup()
{
Serial.begin(9600);
pinMode(
13 , OUTPUT);
Serial.begin(9600);
}
void loop()
{
if
(( ( Serial.available() ) > ( 0 ) ))
{
_ABVAR_1_temp
= Serial.read();
if
(( ( _ABVAR_1_temp ) == ('1') ))
{
digitalWrite(
13 , HIGH );
Serial.print(
"LED ON" );
Serial.println();
}
else
{
if
(( ( _ABVAR_1_temp ) == ('0') ))
{
digitalWrite(
13 , LOW );
Serial.print(
"LED OFF" );
Serial.println();
}
else
{
Serial.print(
"ERROR!" );
Serial.println();
}
}
}
}
其中的指令”讀取序列Serial.read”為讀取1個字元,
沒有留言:
張貼留言