본문 바로가기

Arduino

superloop ADC_BT serial

superloop_ADC.ino

int potentiometer_en = 0;
int tmp36sensor_en = 0;
int photosensor_en = 0;
int distancesensor_en = 0;

void setup() {
//  serial_setup();
  BTserial_setup();  
  potentiometer_setup();
  tmp36sensor_setup();
  photosensor_setup();
  distancesensor_setup();
}

void loop() {
//  serial_loop();
  BTserial_loop();
  if(potentiometer_en == 1) 
    potentiometer_loop();
  if(tmp36sensor_en == 1) 
    tmp36sensor_loop();
  if(photosensor_en == 1) 
    photosensor_loop();
  if(distancesensor_en == 1) 
    distancesensor_loop();
}

BTserial.ino

# include <SoftwareSerial.h>  
int BT_TX = 2;
int BT_RX = 3;
int userCmd =0;

SoftwareSerial BTSerial(BT_TX, BT_RX);

void BTserial_showMenu() {
  Serial.println("1. Potentiomter Led Brightness Enable/Disable");
  Serial.println("2. Tmperature sensor Led Blink Enable/Disable");
  Serial.println("3. Photo Sensor RGB Led On/Off Enable/Disable");
}
void BTshowMenu() {
  Serial.println("1. Potentiomter Led Brightness Enable/Disable");
  Serial.println("2. Tmperature sensor Led Blink Enable/Disable");
  Serial.println("3. Photo Sensor RGB Led On/Off Enable/Disable");
}

void BTserial_setup() {
Serial.begin(9600);  
BTSerial.begin(9600);
BTserial_showMenu();
BTshowMenu();
}

void BTserial_loop() {
  if(BTSerial.available()>0) {    
    userCmd = BTSerial.read();
    BTserial_switch(userCmd);
  }
  if(Serial.available()>0) {  
    userCmd = Serial.read();
    BTserial_switch(userCmd);
  }
}

void BTserial_switch(int userCmd)
{
    switch(userCmd) {
      case '1': potentiometer_en = !potentiometer_en;    break;
      case '2': tmp36sensor_en = !tmp36sensor_en;        break; 
      case '3': photosensor_en = !photosensor_en;        break;
      case '4': distancesensor_en = !distancesensor_en;  break;
      default: break;
    }
}

 

https://geagolas.tistory.com/43 에서 superloop_ADC.ino 수정, BTserial.ino 추가한 코드

'Arduino' 카테고리의 다른 글

superloop PWM  (0) 2022.03.22
superloop ADC  (0) 2022.03.18
Interrupt를 이용한 btn_toggle  (0) 2022.03.17
BT input  (0) 2022.03.15
LED control with SerialRead  (0) 2022.03.14