Sunday, July 10, 2005

5LED blink and assign speed-change & switch with 2 potentiometers

'Set 5LEDs to portd.1, portd.0, portc.3, portc.2, portc.1 and set potentiometer (dail) to RA1, set potentiometer (slider) to RA0

' 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 potentionmeter (slider) set into porta.0
' Create variable to store result
'ADCvar1 means potentionmeter (dial) set into porta.1
' 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 (This is another circuit)
input portb.0
'defining portb.7 as OUTPUT (This is another circuit)
output portb.7

Pause 500
' Wait .5 second

'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
'Define Switchvar, equation order is important. Do not write down here as portb.7=switchvar
portb.7 = switchVar

if ADCVAR0 < 500 then
'If the potentiometer (slider) is less than 500
speedVar = (ADCvar1 / 4) +10
'Speed (LED-blink) will be changed with dialing of potentiometer (dial)
'everytime (devided by 4) plus 10 in order to NOT get NO-RESULT
high portd.1
pause speedvar
'instead of PAUSE 200 (We may write down PAUSE 200 here instead of PAUSE speedvar)
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

GoTo main
' Do it forever


Post a Comment

<< Home