View unanswered posts | View active topics It is currently Thu Nov 27, 2014 12:25 am






Reply to topic  [ 6 posts ] 
different???? 
Author Message
Rookie

Joined: Mon Sep 17, 2007 5:31 am
Posts: 28
Location: Indonesia
Post 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
Profile YIM
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post 
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
Profile WWW
Rookie

Joined: Mon Sep 17, 2007 5:31 am
Posts: 28
Location: Indonesia
Post ....
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
Profile YIM
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post 
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
Profile WWW
Rookie

Joined: Mon Sep 17, 2007 5:31 am
Posts: 28
Location: Indonesia
Post 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
Profile YIM
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post 
//*!!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
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 6 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.