printf("ho_tari\n");

04_Serial_Read 본문

Arduino

04_Serial_Read

호타리 2023. 9. 2. 12:34
const int LED_0 = 13;
const int LED_1 = 12;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  pinMode(LED_0, OUTPUT);
  pinMode(LED_1, OUTPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  if(Serial.available()){
    char userInput[30] = {0, };
    Serial.readBytesUntil('\n', userInput, 30);

    if(strcmp("L0_ON", userInput) == 0){
      digitalWrite(LED_0, HIGH);
    }
    else if(strcmp("L0_OFF", userInput) == 0){
      digitalWrite(LED_0, LOW);
    }
    else if(strcmp("L1_ON", userInput) == 0){
      digitalWrite(LED_1, HIGH);
    }
    else if(strcmp("L1_OFF", userInput) == 0){
      digitalWrite(LED_1, LOW);
    }
  }

}

'Arduino' 카테고리의 다른 글

06_Switch_Input_Interrupt  (0) 2023.09.02
05_Switch_Input  (0) 2023.09.02
03_Analog_Write  (0) 2023.09.02
02_LED_ON_OFF  (0) 2023.09.02
01_Serial_print  (0) 2023.09.02