Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help! I am trying to add a motor to this code on pin 2 How do I add a sec

ID: 3550874 • Letter: P

Question

Please help!

I am trying to add a motor to this code on pin 2

How do I add a second codition such as and (&&)? maybe


LED is on 13, Button is on 5, Motor is on 2


Here is the code

a = arduino('COM4');


a.pinMode(13,'OUTPUT');

a.pinMode(5,'INPUT');

a.pinMode(2,'OUTPUT');


loop=1;

val=0;


while loop==1


    val=a.digitalRead(5); % reads pin 5

    

    if val==1

        a.digitalWrite(13,1) && <---------------Not Sure

        a.digitalWrite(2,1);<---------------Not Sure

        

    else

        a.digitalWrite(13,0) &&   <---------------Not Sure

        a.digitalWrite(2,0);     <---------------Not Sure

    end


end

Explanation / Answer

a = arduino('COM4');


a.pinMode(13,'OUTPUT');

a.pinMode(5,'INPUT');

a.pinMode(2,'OUTPUT');


loop=1;

val=0;


while loop==1


val=a.digitalRead(5); % reads pin 5

if val==1

a.digitalWrite(13,1);

a.digitalWrite(2,1); %no && is required all statements before ENDare executed

else

a.digitalWrite(13,0);

a.digitalWrite(2,0); %no && is required all statements befor ENDare executed

end


end