Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

Commit

Permalink
feat: add setUSPins() to allow overriding distance sensor pins (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
sverben authored Mar 4, 2024
1 parent fd7ff79 commit c1dba90
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Leaphy Original Extension
version=0.0.2
version=0.0.3
author=Leaphy Robotics
maintainer=Leaphy Robotics <[email protected]>
sentence=Provides functionality to program Leaphy Original robots
Expand Down
17 changes: 12 additions & 5 deletions src/Leaphyoriginal1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,25 @@ void setMotorPins(int m1_pwm, int m1_dir, int m2_pwm, int m2_dir)
}


void setUSPins(int echo, int trig)
{
us_pins.echo = echo;
us_pins.trig = trig;
}


float getDistance()
{
float duration, distance;
int tries = 0;

pinMode(US_TRIG, OUTPUT);
digitalWrite(US_TRIG, LOW);
pinMode(us_pins.trig, OUTPUT);
digitalWrite(us_pins.trig, LOW);
delayMicroseconds(2);
digitalWrite(US_TRIG, HIGH);
digitalWrite(us_pins.trig, HIGH);
delayMicroseconds(10);
digitalWrite(US_TRIG, LOW);
duration = pulseIn(US_ECHO, HIGH, 30000);
digitalWrite(us_pins.trig, LOW);
duration = pulseIn(us_pins.echo, HIGH, 30000);
distance = 0.034 * duration / 2;
if(distance == 0 ){
distance = distance + 1313;
Expand Down
8 changes: 6 additions & 2 deletions src/Leaphyoriginal1.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
#define LED1_BLUE (3) // PWM-OUT
#define LINE_LEFT (16) // DIG-IN A2 tinkerkit In2
#define LINE_RIGHT (17) // DIG-IN A3 tinkerkit In3
#define US_ECHO (8) // DIG-IN/OUT
#define US_TRIG (7) // DIG-OUT

struct {
int m1_pwm = 10;
Expand All @@ -42,7 +40,13 @@ struct {
int m2_dir = 13;
} motor_pins;

struct {
int echo = 8;
int trig = 7;
} us_pins;

void setMotorPins(int m1_pwm, int m1_dir, int m2_pwm, int m2_dir);
void setUSPins(int echo, int trig);
float getDistance();
int getLineFollower(int fpSide);
void setTone( int fpTone, int fpBeat);
Expand Down

0 comments on commit c1dba90

Please sign in to comment.