Monday, July 04, 2005

Analog Input with 2 Pots & Switch--5 LED blink


' PicBasic Pro program to display result of'
10-bit A/D conversion through serial at 9600 baud
' Connect analog input to channel-0 (RA0)
' Define ADCIN parameters
DEFINE ADC_BITS 10
' Set number of bits in result
DEFINE ADC_CLOCK 3
' Set clock source (3=rc)
DEFINE ADC_SAMPLEUS 50
' Set sampling time in uS

'ADCvar0 means potentiometer(slider) porta.0
ADCvar0 VAR WORD
' Create variable to store result

'ADCvar1 means potentiometer (dial) porta.1
ADCvar1 VAR WORD
' Create variable to store result

TRISA = %11111111
' Set PORTA to all input
ADCON1 = %10000010
' Set PORTA analog and right justify result

'this defines a variable for the switch
switchVar var byte
'this defines a variable for the speed
speedVar var word
'speedvar = 200

'defining portb.0 as INPUT (---LED is set into portb.0)
input portb.0
'defining portb.7 as OUTPUT (---Switch is set into portb.7)
output portb.7

Pause 500
' Wait .5 second

main:
'ADCIN Channel,Variablename
ADCIN 0, ADCvar0
' Read channel 0 to adval
ADCIN 1, ADCvar1
' Read channel 1 to adval

serout2 PORTC.6, 16468, [DEC ADCvar0, 13, 10]
' print it to serial out,
' with linefeed and carriage return (10, 13)

'this code means portb.7 = the state of the switch (condition)
switchVar = portb.0
portb.7 = switchVar

if ADCVAR0 < 500 then
speedvar = (ADCvar1 / 4) +10
'everytime (devided by 4) plus 10 means, in order to NOT get NO-RESULT when we use potentiometer (dial).

high portd.1
pause speedvar
'instead of PAUSE 200
low portd.1
pause speedvar
high portd.0
pause speedvar
low portd.0
pause speedvar
high portc.3
pause speedvar
low portc.3
pause speedvar
high portc.2
pause speedvar
low portc.2
pause speedvar
high portc.1
pause speedvar
low portc.1
pause speedvar
endif
GoTo main
' Do it forever

0 Comments:

Post a Comment

<< Home