Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

自走車程式碼 #1

Open
Andy87877 opened this issue Dec 7, 2024 · 0 comments
Open

自走車程式碼 #1

Andy87877 opened this issue Dec 7, 2024 · 0 comments

Comments

@Andy87877
Copy link
Owner

int _ABVAR_1_Speed = 0 ;
int _ABVAR_2_Speed = 0 ;

int ardublockUltrasonicSensorCodeAutoGeneratedReturnCM(int trigPin, int echoPin)
{
long duration;
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(20);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
duration = duration / 59;
if ((duration < 2) || (duration > 300)) return false;
return duration;
}

void setup()
{
pinMode( 11, OUTPUT);
pinMode( 5, OUTPUT);
pinMode( 6, OUTPUT);
pinMode( 10, OUTPUT);
digitalWrite( 4 , LOW );

_ABVAR_1_Speed = 190 ; // left
_ABVAR_2_Speed = 240 ; // right

}

void loop()
{
if (( ( ardublockUltrasonicSensorCodeAutoGeneratedReturnCM( 4 , 7 ) ) > ( 10 ) ))
{
analogWrite(5 , 0);
analogWrite(6 , _ABVAR_1_Speed);
analogWrite(11 , 0);
analogWrite(10 , _ABVAR_2_Speed);
}
if (( ( ( ardublockUltrasonicSensorCodeAutoGeneratedReturnCM( 4 , 7 ) ) < ( 10 ) ) && ( ( ardublockUltrasonicSensorCodeAutoGeneratedReturnCM( 4 , 7 ) ) >= ( 8 ) ) ))
{
analogWrite(5 , 0);
analogWrite(6 , 0);
analogWrite(11 , 0);
analogWrite(10 , 0);
}
if (( ( ardublockUltrasonicSensorCodeAutoGeneratedReturnCM( 4 , 7 ) ) < ( 8 ) ))
{
analogWrite(5 , _ABVAR_1_Speed);
analogWrite(6 , 0);
analogWrite(11 , _ABVAR_2_Speed);
analogWrite(10 , 0);
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant