Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e6823cb

Browse files
committed
Simplify arduino script
1 parent dd2fa42 commit e6823cb

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

radar/arduino/sketch.ino

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@
33
#define PWM_ECHO 10
44
#define PWM_SERVO 11
55
#define DELIMITER "\n" // used to separate each message
6-
7-
const int PI_proportion = 90; // Number of PI divisions where the servo stops
8-
const int PI_delay = 10; // Delay (ms) given to the servo to accomplish a PI/PI_proportion angle
6+
#define MEASURE_DELAY 2 // Delay (ms) given to the servo to accomplish a distance measure
97

108
long duration;
119
int distance;
@@ -29,6 +27,13 @@ int measureDistance(){
2927
return duration*0.034/2; // in cm;
3028
}
3129

30+
void getMeasure(int angle){
31+
servo.write(angle);
32+
delay(MEASURE_DELAY);
33+
distance = measureDistance();
34+
sendData(angle, distance);
35+
}
36+
3237
void sendData(int a, int d){
3338
Serial.print(a);
3439
Serial.print(",");
@@ -53,19 +58,11 @@ void setup() {
5358

5459
void loop() {
5560

56-
for (int piRatio = 0; piRatio <= PI_proportion; piRatio++){
57-
angle = map(piRatio, 0, PI_proportion, 0, 180);
58-
servo.write(angle);
59-
delay(PI_delay);
60-
distance = measureDistance();
61-
sendData(angle, distance);
61+
for (int angle = 0; angle <= 180; angle++){
62+
getMeasure(angle);
6263
}
63-
for (int piRatio = 0; piRatio <= PI_proportion; piRatio++){
64-
angle = map(piRatio, 0, PI_proportion, 180, 0);
65-
servo.write(angle);
66-
delay(PI_delay);
67-
distance = measureDistance();
68-
sendData(angle, distance);
64+
for (int angle = 180; angle >= 0; angle--){
65+
getMeasure(angle);
6966
}
7067

7168
}

radar/radar-ui/src/Main.elm

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,11 @@ polarToCartesianCoord ( angle, distance ) =
5454
x =
5555
distance
5656
|> (*) (cos (degrees angle))
57-
|> floor
5857
|> zoom
5958

6059
y =
6160
distance
6261
|> (*) (sin (degrees (angle + 180)))
63-
|> floor
6462
|> zoom
6563
in
6664
( x, y )

radar/radar-ui/src/Types.elm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type alias Distance =
1212

1313

1414
type alias CartesianCoord =
15-
( Int, Int )
15+
( Float, Float )
1616

1717

1818
type alias PolarCoordRecord =

0 commit comments

Comments
 (0)