Ball and beam c code help?

hello guys anybody can help me to complate this code?

#include<16F877A.h>
#fuses HS, NOWDT, NOPROTECT, NOLVP
#use delay (clock=20000000)
#use rs232(baud=19200,xmit=PIN_C6,rcv=PIN_C7)
#include <stdlib.h>
#include <input.C>
#use fast_io(B)
#use fast_io(D)
#org 0x1F00,0x1FFF{}
#opt 9

void main(){
//define your variables here;
int16 time;
long a;

//set_tris for servo pin here;

setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);

printf(“Program Starts!!!\n\r”);

while(TRUE){
delay_ms(1);
//////////setting the US sensor////////
set_tris_b(0b00000000);
output_high(US);
delay_us(5);
output_low(US);
set_tris_b(0b01000000);
/////////////////////////////////////////

////////////*calculating the duration////
delay_us(500);
while (!input(US)){ };
set_timer1(0);
while (input(US)){ };
time = get_timer1();
delay_us(5);
///////////calculating the distance in cm’s/////
a=(long)((float)time/10
0.034);
printf("%lu\n\r",a);
/////////////////////////////////////////////////

if (“condition1”){ //set your condition according to position of the ball
//do nothing
}
else if (“condition2”){ //set your condition according to position of the ball
//CW-OR-CCW
calculate your servo duty with proportional and derivative gains according to distance
}
else if (“condition3”){ //set your condition according to position of the ball
//CCW-OR-CW
calculate your servo duty with proportional and derivative gains according to distance
}

printf("-----duty=%lu\n\r",duty);

for(i=0;i<10;i++)
{
output_high(SERVO);
delay_us(duty);

output_d(0);
delay_ms(20);
}

//delay_ms(100);
}
}

So you want some one else to do your homework? I hope we get a good grade.

I tried to do but i did not:(( i just did my hardware part and i used servo motor and sensor and I think i have to use PD controller code but how and how to write sensor code? if anybody help me to complate this i will pass the course:D

Help is fine, doing it for you is not.

how to write sensor code

A sensor is a device that will turn one physical effect into another. What is your sensor and what signal does it present to the arduino?

Assume your sensor is an analogue signal and you have it connected to an analogue input pin.

  1. Read the pin and get a number corresponding to the sensors position.
  2. Use the ‘if’ statement or the switch construct to do things when the sensor’s number is at a certain value or range of values. For example to light an LED on pin 5 when the analogue pin 0 is between 200 to 600 inclusively then:-

sens = analogRead(0);
if((sens > 199) && (sens <601)) { digitalWrite(5,HIGH); }

include<16F877A.h>

I think someone is in the wrong forum. :-?

i used Ultrasonic Sensor and i connected to PIC 16F877A RB6/PGC. I am so panic and confused:S

That code is CCS format code for PIC chips. You really should go to:

www.ccsinfo.com/forum/ and ask there

I'm a member over there (hence how I know what compiler was used for your code) so maybe I'll reply over there.

ok adderD thnk you i will ask there i hope i will learn the code:(