코드 |
좋아요:0 | ||||
---|---|---|---|---|---|
작성자 | 김민희 | 등록일 | 18.06.02 | 조회수 | 138 |
#define TRIG 2 #define ECHO 5 #define WHITE 13 void setup() { pinMode(TRIG ,OUTPUT); // TRIG pinMode(ECHO, INPUT); // INPUT } void loop() { digitalWrite(TRIG. LOW); delayMicroseconds(2); digitalWrite(TRIG. HIGH); delayMicroseconds(10); digitalWrite(TRIG. LOW); long distance = pulseln(ECHO, HIGH)/58.2; analogWrite(WHITE,0); if(distance<10){ analogWrite(WHITE, 255); } delay(100); } void setup() { pinMode(8, OUTPUT); pinMode(9, INPUT); Serial.begin(9600); } void loop() { digitalWrite(8, LOW); delayMicroseconds(1); digitalWrite(8, HIGH); delayMicroseconds(1); digitalWrite(8, LOW); long a=pulseIn(9, HIGH)/58.2; Serial.print("측정된 거리는 : "); Serial.print(a); Serial.println(" cm입니다."); delay(500); } |
이전글 | 3D 돌림판 냉장고 자료 |
---|---|
다음글 | 연습 (1) |