static int turned =0; CY_ISR(GPIO_PSOC1_IN_HANDLER){ stop(); CyDelay(100); left(
ID: 1996399 • Letter: S
Question
static int turned =0;
CY_ISR(GPIO_PSOC1_IN_HANDLER){
stop();
CyDelay(100);
left();
if(turned=0){
left();
turned=1;
}
else if(turned =1;){
right();
right(); //180 degree turn
turned =2;
}
else{
right();
turned=0;
GPIO_PSOC1_Out_Write(1);
GPIO_PSOC1_In_ClearInterrupt();
}
Hi, I'm trying to program my Psoc 5LP to make turns when receiving signals from an Ultrasonic Sensor. Everything seems to be working, I just can't get the DC Motors to make left and right turns. Can anyone help me figure out my problem? The turned = 1 doesnt seem to execute in the else if statement. Thanks
Explanation / Answer
In line number 6 and 10, the condition checking statement using "equals" operator is not correct.
Instead of this for line 6
if(turned=0){
it should have been this
if(turned==0){
Instead of this for line 10
else if(turned =1;){
it should have been this
else if(turned ==1){
For line 10, the semicolon after 1 is also a serious mistake.
"==" is the operator for checking equality, "=" is the assignment operator.
So basically what you were doing was not checking the value of turned, but assigning the value of 0/1 to turned, which was just evaluating to true or false based on the value of the value assigned(false for 0 and true for 1). So that was making the logical error.
Hope that you got it.
Please comment if you have any issues in understanding or if it is still not working.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.