Device = 18F1220
Clock = 8 // tells the compiler the FOSC speed
Config OSC = INTIO2, WDT = OFF, LVP = OFF, MCLRE = OFF
Include "Utils.bas"
Include "INTOSC8.bas"
Include "ADC.bas"
Dim right1 As PORTA.0
Dim left1 As PORTA.1
Dim highvolts As Word
Dim lowvolts As Word
Dim Counter As Word
Dim hold(2) As byte
Function Get_ADC_Sample() As Byte // Function to grab the ADC sample
result = ADC.Read(0) // Grab an ADC sample from channel 0
//result = result * 2 // Scale the answer up by a factor of 3
End Function
hold(0) = 0
hold(1) = 0
Counter = 0
For Counter = 0 To 1 // loop 2 times
While Get_ADC_Sample > 0 // get sample
Wend
hold(Counter) = Get_ADC_Sample // put in hold()
DelayMS(20) // small delay
Next
SetAllDigital
TRISB =%00000000
PORTB =%00000000
Input(PORTA.0)
While True
highvolts = hold(0)
lowvolts = hold(1)
If highvolts > lowvolts Then // checks to see if highvols is higher
PORTB = %11111111 // lights up portB
DelayMS(20)
Else
PORTB =%00000000 // if not higher turns portB off
DelayMS(20)
EndIf
Wend