블루투스로 아두이노 동작 방법을 선택하여 운영할 수 있을까요?
페이지 정보
작성자 봄빛 작성일20-04-02 15:11 조회6,813회 댓글0건본문
스마트폰으로 아두이노의 동작방법을 변경하며 사용하는 것이 가능할까요?
아래의 코드에서 예를 들어 3의 신호를 보내면 A의 방법으로 동작하고,
4의 신호를 보내면 B의 방법으로 동작하는 방법으로 말입니다.
#include <SoftwareSerial.h>
#include <Wire.h>
#include <DFPlayer_Mini_Mp3.h>
#include <Adafruit_NeoPixel.h>
#include <afstandssensor.h>
#include <TM1637Display.h>
#define las_beam 9
#define select 6
#define led 5
#define CLK 3
#define DIO 4
SoftwareSerial mySerial(10, 11); // RX, TX
SoftwareSerial BTSerial(7, 8); // RX, TX
Adafruit_NeoPixel strip = Adafruit_NeoPixel (8, 5, NEO_GRB + NEO_KHZ800);
AfstandsSensor afstandssensor(13, 12);
TM1637Display display(CLK, DIO);
bool jump = false;
int jump_success = 0;
int running_success = 0;
//
void setup () {
Serial.begin (9600);
mySerial.begin (9600);
BTSerial.begin (9600);
mp3_set_serial (mySerial); //set softwareSerial for DFPlayer-mini mp3 module
delay(1); //wait 1ms for mp3 module to set volume
mp3_set_volume (30);
display.setBrightness(10);
pinMode (las_beam, OUTPUT);
pinMode (select, INPUT);
pinMode (led, OUTPUT);
strip.setBrightness(80);
strip.clear();
strip.begin();
}
//
void loop () {
int val = afstandssensor.afstandCM();
if (digitalRead(select) == HIGH) {
mp3_next();
}
if (BTSerial.available()) {
byte BT_data = BTSerial.read();
Serial.write(BT_data);
if (BT_data =='1') {
digitalWrite(3,HIGH);
}
if (BT_data == '2') {
digitalWrite(3,LOW);
}
if (BT_data == '3') {
kneecount();
}
if (BT_data == '4') {
jumpcount();
}
if (BT_data == '5') {
jump_success == 0;
display.showNumberDec(jump_success, false);
}
}
}
void kneecount() {
int val = afstandssensor.afstandCM();
if ((jump == false) && (val < 50) && (val > 15)) {
jump == true;
jump_success++;
Serial.print("running_success = ");
Serial.println(jump_success);
for(int i=0; i<9; i++) {
strip.setPixelColor (i, strip.Color(255,0,0));
strip.show();
}
delay(150);
for(int i=0; i<9; i++) {
strip.setPixelColor (i, strip.Color(0,0,0));
strip.show();
}
}
}
void jumpcount() {
int val = afstandssensor.afstandCM();
if ((jump == false) && (val < 50) && (val > 15)) {
jump == true;
jump_success++;
Serial.print("jump_success = ");
Serial.println(jump_success);
Serial.print("distance = ");
Serial.println(afstandssensor.afstandCM());
mp3_play();
for(int i=0; i<9; i++) {
strip.setPixelColor (i, strip.Color(255,0,0));
strip.show();
}
delay(5000);
for(int i=0; i<9; i++) {
strip.setPixelColor (i, strip.Color(0,0,0));
strip.show();
}
}
}
댓글 : 0
조회수 : 6,813
등록된 댓글이 없습니다.