본문 바로가기

Arduino

BT input

Superloop.ino

int blink_en =1;
int fading_en =1; 
int blinkRGB_en =1;
int fadingRGB_en = 0;

void setup() {
  blink_setup();
  fading_setup();
  blinkRGB_setup();
  fadingRGB_setup();
//  serial_setup();
  BTserial_setup();
}

void loop() { 
  if(blink_en == 1) blink_loop();
  if(fading_en == 1) fading_loop();
  if(blinkRGB_en == 1) blinkRGB_loop();
  if(fadingRGB_en == 1) fadingRGB_loop();
//  serial_loop();
  BTserial_loop();
}

 

BTSerial.ino

# include <SoftwareSerial.h>  
int BT_TX = 2;
int BT_RX = 3;
SoftwareSerial BTSerial(BT_TX, BT_RX);

void showMenu1(){ 
//Serial.println("\033[2J\033[H"); //ANSI escape squence 실행 안됨
Serial.println( " 1.Led Blink Enable/Disable " ); 
Serial.println( " 2.Led Fading Enable/Disable " ); 
Serial.println( " 3.RGB Led Blink/Fading Toggle " ); 
}
void showMenu2(){ 
//BTSerial.println("\033[2J\033[H");  //ANSI escape squence 실행 안됨
BTSerial.println( " 1.Led Blink Enable/Disable " ); 
BTSerial.println( " 2.Led Fading Enable/Disable " ); 
BTSerial.println( " 3.RGB Led Blink/Fading Toggle " ); 
}  

void BTserial_setup(){
Serial.begin(9600); 
showMenu1();
BTSerial.begin(9600);
showMenu2();
} 
int iUserCmd1=0;

void BTserial_loop(){
  if(BTSerial.available()>0){
    iUserCmd1=BTSerial.read();
    switch(iUserCmd1){
    case'1':blink_en=!blink_en;
    BTSerial.print("blink_en : ");
    BTSerial.println(blink_en);
    Serial.print("blink_en : ");
    Serial.println(blink_en);
    break;
    case'2':fading_en=!fading_en;
    BTSerial.print("fading_en : ");
    BTSerial.println(fading_en);
    Serial.print("fading_en : ");
    Serial.println(blink_en);
    break;
    case'3':blinkRGB_en=!blinkRGB_en;
    fadingRGB_en = !blinkRGB_en;
    BTSerial.print(" blinkRGB_en : ");
    BTSerial.print(blinkRGB_en);
    BTSerial.print(" // fadingRGB_en : ");
    BTSerial.println(fadingRGB_en);
    Serial.print(" blinkRGB_en : ");
    Serial.print(blinkRGB_en);
    Serial.print(" // fadingRGB_en : ");
    Serial.println(fadingRGB_en);
    break;
    default : break;
    }
  }
  if (Serial.available()>0){
    iUserCmd1=Serial.read();
    switch(iUserCmd1){
    case'1':blink_en=!blink_en;
    BTSerial.print("blink_en : ");
    BTSerial.println(blink_en);
    Serial.print("blink_en : ");
    Serial.println(blink_en);
    break;
    case'2':fading_en=!fading_en;
    Serial.print("fading_en : ");
    Serial.println(fading_en);
    BTSerial.print("fading_en : ");
    BTSerial.println(fading_en);
    break;
    case'3':blinkRGB_en=!blinkRGB_en;
    fadingRGB_en = !blinkRGB_en;
    BTSerial.print(" blinkRGB_en : ");
    BTSerial.print(blinkRGB_en);
    BTSerial.print(" // fadingRGB_en : ");
    BTSerial.println(fadingRGB_en);
    Serial.print(" blinkRGB_en : ");
    Serial.print(blinkRGB_en);
    Serial.print(" // fadingRGB_en : ");
    Serial.println(fadingRGB_en);
    break;
    default : break;
    }
  }
}

'Arduino' 카테고리의 다른 글

superloop ADC  (0) 2022.03.18
Interrupt를 이용한 btn_toggle  (0) 2022.03.17
LED control with SerialRead  (0) 2022.03.14
RGB_fading  (0) 2022.03.11
RGB_Blink  (0) 2022.03.11