Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int trigger = 7;
- int echo = 6;
- void setup() {
- // put your setup code here, to run once:
- pinMode(trigger, OUTPUT);
- pinMode(echo, INPUT);
- Serial.begin(9600);
- pinMode(11, OUTPUT);
- }
- void loop() {
- // put your main code here, to run repeatedly:
- digitalWrite(trigger, LOW);
- delayMicroseconds(2);
- digitalWrite(trigger, HIGH);
- delayMicroseconds(10);
- digitalWrite(trigger, LOW);
- long time = pulseIn(echo, HIGH);
- long distance = time * 0.034 / 2;
- Serial.println(distance, 3);
- Serial.println(distance % 256, 3);
- analogWrite(11, distance % 256);
- delay(300);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement