View unanswered posts | View active topics It is currently Thu Oct 30, 2014 8:02 pm






Reply to topic  [ 2 posts ] 
Compass 
Author Message
Novice

Joined: Tue Jan 13, 2009 5:22 pm
Posts: 72
Location: USA, Pennsylvania
Post Compass
I know how to use the compass except one thing.
Could someone make a program "if value is between 100 and 200 make sound".

My Compass program:
Quote:
#pragma config(Sensor, S1, Compass, sensorI2CHiTechnicCompass)
//*!!Code automatically generated by 'ROBOTC' configuration wizard !!*//

task main()

{

while(true)

{

if (SensorValue(Compass)>=180)

{

PlayTone(1000, 10);

}

else

{

PlayTone(200, 10);

}

}

}

_________________
We need a Linux Version!


Fri Feb 13, 2009 6:03 pm
Profile WWW
Novice

Joined: Fri Oct 24, 2008 8:58 am
Posts: 87
Post Re: Compass
Quote:
Could someone make a program "if value is between 100 and 200 make sound".


you're almost there just need to have both the bottom limit and the top limit in the same if statement.
Also I'll use a variable to temporarily store the value of the compass.

Code:
task main()
{
  int myCompassValue;

  while(true)
  {
      myCompassValue = SensorValue[S1];

      if(myCompassValue > 100 && myCompassValue < 200)
      {
           PlaySound(soundBeepBeep);
      }

  }

}



So there's your code, it should do what you want. Although it'll beep continuously when between 100 and 200. If you just want it to beep once, thats a pretty easy fix.

One thing and please don't take this the wrong way. I'm happy to help with as many programming questions as you have, but this is really really basic "C" stuff. I recommend reading up on how to program in C or C++. It'll help this all make alot more sense.

I like this book (because its both good and free): http://greenteapress.com/thinkcpp/.


Fri Feb 13, 2009 9:47 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 2 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.