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

Hardware: Sensor 1: Light sensor Sensor 2: Touch sensor OUT_C : Left motor OUT_A

ID: 3862295 • Letter: H

Question

Hardware:

Sensor 1: Light sensor

Sensor 2: Touch sensor

OUT_C : Left motor

OUT_A : Right motor

Write a NXC program for the NXT to continuously wait for a Bluetooth wireless message and perform the task once according to the table below:

Message

Tasks

1

Go Forward for 0.5 sec

2

Go Backward for 0.5 sec

3

Turn Left for 0.5 sec

4

Turn Right for 0.5 sec

5

Play a tone: Note A for 0.5 sec.

6

If Light SENSOR_1 is on black, increment variable cnt, and display cnt value on the LCD. cnt is initially 0. (Use NumOut function to display the cnt value.)

7

Go forward until touch (SENSOR_2 hits something).

8

Go forward from white space, cross a black strip, and stop

Message

Tasks

1

Go Forward for 0.5 sec

2

Go Backward for 0.5 sec

3

Turn Left for 0.5 sec

4

Turn Right for 0.5 sec

5

Play a tone: Note A for 0.5 sec.

6

If Light SENSOR_1 is on black, increment variable cnt, and display cnt value on the LCD. cnt is initially 0. (Use NumOut function to display the cnt value.)

7

Go forward until touch (SENSOR_2 hits something).

8

Go forward from white space, cross a black strip, and stop

Explanation / Answer

task music()

{

while(true)

{

PlayTone(262,400) ; // 5.play a tone

Wait(500);

}

}

task movement()

{

int move_time = 0.5;

int turn_time = 0.5;

OnFwd(OUT_A,75); //go forward to 0.5 sec

OnFwd(OUT_C,75);

Wait(move_time);

OnRev(OUT_AC,75); // backword 0.5 sec

Wait(move_time);

while(true)

{

OnFwd(OUT_AC,75);

Wait(move_time);

if (Random()>=0)

{

OnRev(OUT_A,75); // turn right

}

else {

OnRev(OUT_C,75); // turn left

}

Wait(turn_time);

}

SetSensor(IN_1,SENSOR_TOUCH); // if touch something

OnFwd(OUT_AC,75);

until (SENSOR_1==1);

Off(OUT_AC);

}

task main()

{

Precedes(music,movement); // play music and task

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote