답변 : 아두이노 print write 차이점
페이지 정보
작성자 master 작성일18-06-17 03:35 조회8,785회 댓글2건본문
// MCU BASIC: https://www.basic4mcu.com
// DateTime : 2018-06-17 오전 3:38:21
// by Ok-Hyun Park
//
-------------------------아두이노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=>100
//Serial.println(ratio);
Serial.write((int)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);
}
}
댓글 : 2
조회수 : 8,785
두다디다님의 댓글
두다디다 작성일아두이노 1에서 Serial.write 로 컴파일시 call of overloaded 'write(float&)' is ambiguous 라는 에러문구가 나와요..
master님의 댓글
master
수정했으니 다시 돌려보세요