In the middle of that math mess? I don't think it's a good spot for it...but that's just me...I wrote a new code to protect values which makes out of range.
Code:DEFINE LCD_DREG PORTB DEFINE LCD_DBIT 0 DEFINE LCD_RSREG PORTB DEFINE LCD_RSBIT 4 DEFINE LCD_EREG PORTB DEFINE LCD_EBIT 5 DEFINE LCD_BITS 4 DEFINE LCD_LINES 2 DEFINE OSC 4 DEFINE ADC_BITS 8 DEFINE ADC_CLOCK 3 DEFINE ADC_SAMPLEUS 100 f var porta.0 : g var porta.1 : alta var byte : usta var byte : altb var byte ustb var byte : t var byte : i var byt e: adcon1=2 : trisa=3 : trisb=0 portb=0 : trisc=0 : pause 1000 : lcdout $fe,1 : pause 4000 adcin 0,ALTa : ADCin 1,usta : t=150 pulsout portc.2,t 'initial servo kick to center yap: adcin 0,altb : adcin 1,ustb if ((((usta+10)*100)/(ustb+10)))>130 and (not (t>194)) then T=T+15 if (((alta*100)/altb))>130 AND (not (t<51)) then T=T-15 'bounds checking... if t < 100 then t=100 if t > 200 then t=200 'bounds checking 'if 100 isn't low enough, change it, if 200 isn't high enough, change it gosub motor : lcdout $fe,2,#usta," ",#ustb," ",#altA," ",#altb, $fe,$C0,#T goto yap motor: for i=0 to 25 : PULSOUT PORTC.2,T : PAUSEUS 20000-(T*10) : next i return end




Bookmarks