| Author |
Message |
|
suwandi_wieming
Rookie
Joined: Mon Sep 17, 2007 5:31 am Posts: 28 Location: Indonesia
|
 different????
I want to ask...
what the different between
SetSensorType(S1,sensorTouch)
and
const tSensors touchSensor1 = (tSensors) S1;
who is the most useful and easy to understand???
pliz,give me a example....
thanks...
|
| Sun Sep 23, 2007 11:04 pm |
|
 |
|
starwarslegokid
Moderator
Joined: Wed Jan 31, 2007 3:39 am Posts: 298 Location: San Diego, California. USA
|
SetSensorType(S1,sensorTouch)
This one defines port S1 as a touch sensor. You must define all sensor ports being used.
const tSensors touchSensor1 = (tSensors) S1;
This one makes the variable touchSensor1 equal to the value of the sensor pluged into port S1. It does not define the sensor port like the other one does.
If you were to write code to read a sensor, here is what it might look like
Task main ()
{
SetSensorType(S1,sensorTouch)
//make port S1 a touch sensor, must have//
const tSensors touchSensor1 = (tSensors) S1;
//makes the variable touchSensor1 equal to sensor in S1
while (true)
{
If (touchSensor1 ==1) //read the touch sensor//
{
PlayTone(2000, 10);
}
}
}
Here ya go B-)
Scott
_________________Mmmm Legos B-) My Robot Projects: http://www.freewebs.com/robotprojects/
|
| Wed Sep 26, 2007 12:27 pm |
|
 |
|
suwandi_wieming
Rookie
Joined: Mon Sep 17, 2007 5:31 am Posts: 28 Location: Indonesia
|
 ....
according from your program,it must work...
your program have a little wrong but it is not the problem...
the problem is when it not read the touch sensor...
i do not know how can it be...
i'm still confuse...
thanks....
|
| Wed Sep 26, 2007 10:35 pm |
|
 |
|
starwarslegokid
Moderator
Joined: Wed Jan 31, 2007 3:39 am Posts: 298 Location: San Diego, California. USA
|
Sorry, I wrote the code at school, could not compile it for bugs. AHA! I made a mistake and put that inside the task main. Here is what it should look like.
const tSensors touchSensor1 = (tSensors) S1;
//make port S1 a touch sensor and refers that sensor as touchSensor1. Created if used the Motors and Sensors Wizard//
task main ()
{
SetSensorType(S1, sensorTouch);
//make port S1 a touch sensor, must manually add if not using the Motors and Sensors Wizard//
while (true)
{
if (touchSensor1 ==1) //read the touch sensor//
{
PlayTone(2000, 10);
}
}
}
const tSensors touchSensor1 = (tSensors) S1;
This piece of code is created if you use the Motors and Sensors Setup Wizard. It takes care of defining which sensor goes to wich port, and assigns a name for easy definition
SetSensorType(S1, sensorTouch);
If you do not use the Motors and Setup Wizard, You have to manualy add this code to your projects.
_________________Mmmm Legos B-) My Robot Projects: http://www.freewebs.com/robotprojects/
|
| Thu Sep 27, 2007 12:25 am |
|
 |
|
suwandi_wieming
Rookie
Joined: Mon Sep 17, 2007 5:31 am Posts: 28 Location: Indonesia
|
 understand...
I understand a little...
but I can understand it...
I try your program but still not work...and the last I try and it is successful...
maybe you forget to add sensorvalue(touchSensor1)...
but...whatever,thanks to you to help me...
|
| Thu Sep 27, 2007 10:25 pm |
|
 |
|
starwarslegokid
Moderator
Joined: Wed Jan 31, 2007 3:39 am Posts: 298 Location: San Diego, California. USA
|
//*!!Sensor, S1, TouchSensor1, sensorTouch, , !!*//
//*!! !!*//
//*!!Start automatically generated configuration code. !!*//
const tSensors TouchSensor1 = (tSensors) S1; //sensorTouch //*!!!!*//
//*!!CLICK to edit 'wizard' created sensor & motor configuration. !!*//
task main ()
{
SetSensorType(S2,sensorTouch);
//make port S1 a touch sensor, must have//
while (true)
{
if ( SensorValue[TouchSensor1]==1) //read the touch sensor//
{
PlayTone(2000, 1);
}
if ( SensorValue[S2]==1) //read the touch sensor//
{
PlayTone(2500, 1);
}
}
}
Im sorry for all the mistakes, School is getting to me.
I forgot to use SensorValue[TouchSensor1]
I checked the code and it works now. I setup both ways to setup and read a sensor. Hope this helps, and im sorry for the sloppy code work
Scott B-)
_________________Mmmm Legos B-) My Robot Projects: http://www.freewebs.com/robotprojects/
|
| Fri Sep 28, 2007 12:49 am |
|
|