Basic Programs Lab 1

Standards and Benchmarks

 

Goals:

            To introduce Not Quite C programming

            Increase confidence working with computers and programming

Real World Applications:

            Program 1- Driving your car, estimating delivery times

            Program 2- Light switches, elevator buttons

Program 1- Basic movement

 

  1. Create a new folder in the “My Document’s” folder to save all files in for the semester.

  1. Modify prog1.nqc (the program you opened while going through the Introduction to NQC) so your car goes forward and backward exactly 11 inches (the gray toolbox is about 11 inches long). 

  1. To figure out how long it takes the car to go 11 inches, you most likely used the “guess and check” method.  We now want you to go 8 inches using the formula distance= rate x time.  Using the formula will give an approximate answer.

  1. Now modify your program so your car goes forward 8 inches and then makes a 90o turn.  There are two ways to make the car turn, try to figure them both out. 

  1. Modify your program so that it makes a square.

Helpful Trick

repeat (n)     // n= number of times you want the commands to repeat      

  {

      //the commands you want to repeat         

  }

 

    Program 2 – Working with a bump sensor

 

  1. Open prog2.nqc.  You will find this program in the My Documents folder.  In order to run this program you will need to connect a bump sensor to the RCX.  This sensor is grey with a small yellow button.  On the top of the sensor are 4 bumps with metal showing, cover these 4 bumps with a black connector cable.   The other end of the cable goes on input #1.  You can tell it goes on input #1 because in the program the sensor is defined as SetSensor(SENSOR_1, SENSOR_TOUCH).  Look through this program, decide what you think it will do, compile it, download it, run it, and see if you are correct.

  1. If you were correct, go ahead and modify the program so your bump sensor acts as a brake, stopping your car.  Your car should run when it is not pressed. 

  1. Modify your program so your car hits a wall, then backs up, and turns around.

 

Program 3- Working with a light sensor

 

  1. Now open prog3.nqc.  You don’t need the bump sensor for this program, instead, you need a light sensor; a light sensor is a blue block with an attached cable.  Looking at the program should tell you on what port you should put it.  You want the light sensor to face the ground on the front of the car.  Then continue looking at the program and try to figure out what it does.  Compile it, download it, run it and see if you are right. 

More About the Light Sensor

The light sensor is slightly misnamed.  It doesn’t see ambient light, what it actually does is tells how much light is reflected off a surface.  At times we may refer to this sensor as a reflective sensor for this reason.  Different amounts of light are reflected depending on the color of the object, material of the object, lighting in the area as well as other factors.  To see how much light is being reflected press the black “view” button on the RCX until the small carrot (^) is under the same port the light sensor is on.  You should get a number somewhere between 0 and 100 if you don’t, try compiling, downloading and running your program again.  If you still don’t get between 0-100 ask an assistant for help.

 

    10.   Modify the program (if modification is necessary) to make your car run until it sees the edge of the table and then stops.  Please be ready to catch your car so it doesn’t fall.  You may need to change the threshold to do this.  

 

If you have finished all of the tasks move on to Lab 2.

 

Back to Contents