Touch sensor

Plug the touch sensor into port 1 and run this program to count how many times the touch sensor has been pressed.

import lejos.nxt.*;

public class TestSensor {

	public static void main(String[] args) 
	throws Exception {
	    TouchSensor touch = new TouchSensor(SensorPort.S1);
		int count = 0 ;
		while(count<12){ //loop until the sensor is pressed 12 times
		    if(touch.isPressed()){
				count++;// increment count (add one)
				LCD.clear();
				LCD.drawInt(count, 3, 3);// display the count
				LCD.refresh();
				while ( touch.isPressed())
			    	{}// as long as the button is still depressed just wait
		    	}
	    	}
 	}

} 

Activity:

Modify the program above to play a note with the frequency of 250 to start with and each time the touch sensor is pressed play a note with a frequencey that is 25 higher until the frequency value goes above 500. Have it display the frequency value on the screen as it plays each note. Look at how musical notes are generated if you need help.

Note: another way to ask if the touch sensor has been touched without creating a sensor object is
if (SensorPort.S1.readBooleanValue() == true){// if pressed