Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
robit:sweep_n_scan [2021/02/25 13:00]
john removed
— (current)
Line 1: Line 1:
-<file c sweep_n_scan.ino> 
-#include <Servo.h> 
  
-const int TRIG_PIN = 9; 
-const int ECHO_PIN = 10; 
- 
-float inches; 
- 
-Servo myservo; 
- 
-int pos = 60; 
- 
-void setup() { 
-  myservo.attach(13); 
-  Serial.begin(9600); 
-  pinMode(TRIG_PIN, OUTPUT); 
-  digitalWrite(TRIG_PIN, LOW);   
-} 
- 
-void loop() { 
-  for (pos = 30; pos <= 180; pos += 15) { 
-    myservo.write(pos); 
-    FindRange(); 
-    Serial.print("Angle: "); 
-    Serial.print(myservo.read()); 
-    Serial.print("  Distance: "); 
-    Serial.println(inches); 
-    delay(1000); 
-  } 
-  for (pos = 180; pos >= 30; pos -= 15) { 
-    myservo.write(pos); 
-    FindRange(); 
-    Serial.print("Angle: "); 
-    Serial.print(myservo.read()); 
-    Serial.print("  Distance: "); 
-    Serial.println(inches); 
-    delay(1000); 
-  } 
-} 
- 
-float FindRange () { 
-  unsigned long t1; 
-  unsigned long t2; 
-  unsigned long pulse_width; 
-  float cm; 
-  float inches; 
-   
-  // start finding the distance 
-  digitalWrite(TRIG_PIN, HIGH); 
-  delayMicroseconds(10); 
-  digitalWrite(TRIG_PIN, LOW);   
- 
-  while ( digitalRead(ECHO_PIN) == 0 ); 
- 
-  t1 = micros(); 
-  while ( digitalRead(ECHO_PIN) == 1); 
-  t2 = micros(); 
-  pulse_width = t2 - t1; 
-  inches = pulse_width / 148.0; 
-  return inches;   
-} 
-</file> 
Driven by DokuWiki Recent changes RSS feed Valid CSS Valid XHTML 1.0