int x = 0; long ultrason_11() { long duration, distance; digitalWrite(11,LOW); delayMicroseconds(2); digitalWrite(11, HIGH); delayMicroseconds(10); digitalWrite(11, LOW); duration = pulseIn(12, HIGH); distance = duration/58; return distance; } void setup() { Serial.begin(9600); pinMode(11, OUTPUT); pinMode(12, INPUT); } void loop() { x = ultrason_11(); Serial.println(x); delay(300); }
Открыть пример: Online ArduBlock
int x = 0; long ultrason_10() { long duration, distance; digitalWrite(10,LOW); delayMicroseconds(2); digitalWrite(10, HIGH); delayMicroseconds(10); digitalWrite(10, LOW); duration = pulseIn(10, HIGH); distance = duration/58; return distance; } void setup() { Serial.begin(9600); pinMode(10, OUTPUT); pinMode(10, INPUT); } void loop() { x = ultrason_10(); Serial.println(x); delay(300); }
Открыть пример: Online ArduBlock
Видеоурок: