Source Code Snippets
~Daniel 3-17-04
This is a great program, I was bored after the competition so I wrote it. It uses a sonar, and the knob, and the start and stop buttons to make a great alarm. I though it was kind of neat. Then I was so bored that I even put it on this site.

#define start start_button()
int threats, dis, alarmOn, armed, key, currKey, firstValAve, firstVal1, firstVal2, distance;
int In, Mact, Mdis, ActivateAlarm;

void main()
{
while(1)
{
alarmOn=0;
armed=0;
printf("Press start to ARM\n");
while(!start);
beep();
sleep(0.3);
In = start_process(input());
arm();
Mact = start_process(monitorAcivity());
Mdis = start_process(monitorDisarm());
while(armed);
sleep(3.0);
kill_process(In);
kill_process(Mact);
kill_process(Mdis);
kill_process(ActivateAlarm);
printf("%d Threats So Far\n",threats);
}
}

void arm()
{
int count=10;
printf("Enter KEY\n");
while(!start)
{
sleep(0.2);
if(start)
break;
key=knob();
printf("KEY IS: %d\n",knob());
}
beep();
sleep(1.5);
printf("Change knob NOW PRESS START\n");
while(!start);
currKey=knob();
beep();
printf("arming...");
sleep(0.5);
firstVal1=dis;
printf("...");
sleep(0.5);
printf("....");
sleep(0.5);
firstVal2=dis;
printf("|----ARMED-----\n");
for(count;count>0;count--)
{
printf("%d\n",count);
beep();
sleep(0.5);
}
printf("ARMED\n");
firstValAve=(firstVal1+firstVal2)/2;
armed=1;
tone(1000.0,0.5);
tone(500.0,0.5);
}

void disarm()
{
int keyVal;
printf("Atempting to disarm\n");
sleep(0.5);
while(!start)
{
printf("%d\n",knob());
sleep(0.2);
keyVal = knob();
}
if(keyVal==key)
{
armed=0;
printf("----DISARMED----\n");
sleep(1.0);
tone(500.0,0.5);
tone(1000.0,0.5);
}
else if(!alarmOn)
ActivateAlarm = start_process(PactivateAlarm());
}

void monitorAcivity()
{
while(firstValAve>=(dis-120) && firstValAve<=(dis+120));
ActivateAlarm = start_process(PactivateAlarm());
}

void monitorDisarm()
{
while(armed)
{
while(knob()<=currKey+4 && knob()>=currKey-4);
disarm();
}
}

void input()
{
while(1)
{
sleep(0.12); //I know that this should be 0.3, but that is too long, someone could walk by
dis = sonar();
}
}

void PactivateAlarm()
{
int t;
alarmOn=1;
threats++;
while(armed)
for(t=6000; t>2000; t=t-400)
tone((float)t,0.05);
}

~Daniel
This is a great, simple speed variator.
Depending on how far, or close the sonar is to the cup, or other object, it will change speed, even reserse.

int speed()
{
int s = sonar();
if(s>45)
return s/5;
else if(s<40)
return -(s-40);
else
{
cup++;
return 0;
}
}
//to use it, go like this:
int cup = 0;
while(cup==0)
{
motor(0,speed());
motor(1,speed());
}
ao();

That is all of the code for now.

pick one the bleh
Pick one! Our Mechanical Design snippets that one bleh
you are a bleh IC-4 Source Snippets chain thingys
Some Pictures of stuff
About the FHS team
Links to other sites
My SYS
bleh