BASIC4MCU | 질문게시판 | 블루투스로 목표값 데이터를 전송하고자 합니다.
페이지 정보
작성자 봄빛 작성일2020-04-13 18:07 조회2,825회 댓글0건본문
이곳에서 많은 도움을 받고 있어 감사하다는 말씀을 먼저 드립니다.
첫번째 도움을 요청합니다.
블루투스로 f 값을 받아서 countdown 함수를 반복 수행하고,
첨부된 그림 이미지 중 스마트폰에서 빨간색 1번에 목표값을 아두이노로 전송하여
목표치 만큼 활동을 반복하는 것을 하려고 하는데
무엇이 문제인지 원하는 값 전송이 되지 않습니다.
- 예를 들면 첨부이미지로 100의 값을 전송하면 아두이노에서 100에서 하나씩 작아지는 결과를 원하는 것입니다.
두번째 도움을 요청합니다.
위의 과정을 수행하면서 나타나게 되는 값을 스마트폰으로 다시 전송하려면 어떻게 해야 할까요?
100에서 하나씩 작아진 현재의 숫자를 스마트폰으로 전송하려고 합니다.
이곳을 방문하시는 모든 분들의 건강을 기원합니다.
#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 4SoftwareSerial 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;
int mode = 0;
char val_phone = 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 (10);
display.setBrightness(10);
pinMode (las_beam, OUTPUT);
pinMode (select, INPUT);
pinMode (led, OUTPUT);
strip.setBrightness(80);
strip.clear();
strip.begin();
}
//
void loop () {
if (digitalRead(select) == HIGH) {
mp3_next();
}
if (BTSerial.available()) {
byte BT_data = BTSerial.read();
Serial.write(BT_data);
if (BT_data =='a') {
mode=1;
}
if (BT_data == 'b') {
mode=2;
}
if (BT_data == 'c') {
mode=3;
}
if (BT_data == 'd') {
mode=4;
}
if (BT_data == 'e') {
mode=5;
}
if (BT_data == 'f') {
mode=6;
}
}
if (mode == 1) {
digitalWrite(9,HIGH);
}
if (mode == 2) {
digitalWrite(9,LOW);
}
if (mode == 3) {
kneecount();
}
if (mode == 4) {
jumpcount();
}
if (mode == 5) {
resetcount();
}
if (mode == 6) {
countdown();
}
}void kneecount() {
int val = afstandssensor.afstandCM();
if ((jump == false) && (val < 50) && (val > 15)) {
jump == true;
running_success++;
display.showNumberDec(running_success);
Serial.print("running_success = ");
Serial.println(running_success);for(int i=0; i<9; i++) {
strip.setPixelColor (i, strip.Color(255,0,0));
strip.show();
}
delay(350);
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++;
display.showNumberDec(jump_success, false);
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();
}
}
}void resetcount() {
jump_success = 0;
running_success = 0;
val_phone = 0;
display.showNumberDec(jump_success, false);
}
void countdown() {
int val = afstandssensor.afstandCM();
byte val_phone = BTSerial.read();Serial.write(val_phone);
if ((jump == false) && (val < 50) && (val > 15)) {
jump == true;
val_phone--;
display.showNumberDec(val_phone);
Serial.print("downcount = ");
Serial.println(val_phone);for(int i=0; i<9; i++) {
strip.setPixelColor (i, strip.Color(255,0,0));
strip.show();
}
delay(350);
for(int i=0; i<9; i++) {
strip.setPixelColor (i, strip.Color(0,0,0));
strip.show();
}
}
}
댓글 0
조회수 2,825등록된 댓글이 없습니다.