Hardware Sensor 1 Light sensor Sensor 2 Touch sensor OUTC L

Hardware:

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

C++

Task Description:

From what we have learned so far, the NXT brick can be controlled by an NXC program. It can also be directly controlled by the Bricx command center. Since the NXT brick has the facility to accept messages via the Bluetooth wireless circuitry, we can write an NXC program to let the NXT brick perform a certain task according to messages sent from another NXT brick. Being able to control the NXT using messages has many useful applications such as remote bomb defusing, remote car control, etc.

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

Solution

public category MainActivity extends Activity implements OnClickListener realize the weather
etNum1 = (EditText) findViewById(R.id.etNum1);
etNum2 = (EditText) findViewById(R.id.etNum2);

btnAdd = (Button) findViewById(R.id.btnAdd);
btnSub = (Button) findViewById(R.id.btnSub);
btnMult = (Button) findViewById(R.id.btnMult);
btnDiv = (Button) findViewById(R.id.btnDiv);

tvResult = (TextView) findViewById(R.id.tvResult);

// set a perceiver
btnAdd.setOnClickListener(this);
btnSub.setOnClickListener(this);
btnMult.setOnClickListener(this);
btnDiv.setOnClickListener(this);

}

&&Override
public void onClick(View v) technique stub
float num1 = 0;
float num2 = 0;
float result = 0;

// check if the fields square measure empty
if (TextUtils.isEmpty(etNum1.getText().toString())
|| TextUtils.isEmpty(etNum2.getText().toString()))

// browse EditText and fill variables with numbers
num1 = Float.parseFloat(etNum1.getText().toString());
num2 = Float.parseFloat(etNum2.getText().toString());

// defines the button that has been clicked and performs the corresponding operation
// write operation into oper, we are going to use it later for output
switch (v.getId())

Hardware: Sensor 1: Light sensor Sensor 2: Touch sensor OUT_C : Left motor OUT_A : Right motor C++ Task Description: From what we have learned so far, the NXT b
Hardware: Sensor 1: Light sensor Sensor 2: Touch sensor OUT_C : Left motor OUT_A : Right motor C++ Task Description: From what we have learned so far, the NXT b

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site