BASIC4MCU | 질문게시판 | 아두이노간 시리얼 통신 센서값이 끊어져나와요.
페이지 정보
작성자 두다디다 작성일2018-06-17 03:12 조회6,941회 댓글0건
https://www.basic4mcu.com/bbs/board.php?bo_table=gac&wr_id=5536
본문
아두이노 - 아두이노 간 통신을하려구하는데
센서값이 한숫자한숫자 끊어서 넘어와요..저기 센서에서 넘어오는 값을 비교해야되는데 붙여서 볼순없을까요..?아두이노1-------------------------int pin = 4;unsigned long duration;unsigned long starttime;unsigned long sampletime_ms = 30000;//sampe 30s ;unsigned long lowpulseoccupancy = 0;float ratio = 0;void setup(){Serial.begin(9600);pinMode(4,INPUT);starttime = millis();//get the current time;}void loop(){duration = pulseIn(pin, LOW);lowpulseoccupancy = lowpulseoccupancy+duration;if ((millis()-starttime) > sampletime_ms)//if the sampel time == 30s{ratio = lowpulseoccupancy/(sampletime_ms*10.0); // Integer percentage 0=>100Serial.println(ratio);lowpulseoccupancy = 0;starttime = millis();}}아두이노2---------------------------------char inside;void setup() {Serial.begin(9600);}void loop() {if(Serial.available() > 0){inside = Serial.read();Serial.println(inside);}}저값만 아두이노로 받으면되는데만약 값이 21.21이면21.21이렇게떠요.. 으아아아아어려워요..
댓글 0
조회수 6,941등록된 댓글이 없습니다.