Analog / Digital Input, Output
This is an example of using 2 variable resistors as analog inputs and a switch as a digital input to control 8 LEDs with a PIC18F452 chip. Variable resistor 1 is used to control which LEDs light up. The second variable resistor controls how fast the LEDs blink. The switch decides whether the LEDs blink or not. MAX232CPE is used to allow serial communication with a computer. PICBASIC was used to program the chip. This is how the board was set up:
The following is the code:
DEFINE LOADER_USED 1
DEFINE OSC 20
INCLUDE “modedefs.bas”
DEFINE ADC_BITS 10
DEFINE ADC_CLOCK 3
DEFINE ADC_SAMPLEUS 20
ADCON1 = %10000010
TRISA = %11111111
TRISB = %00000000
TRISC = %10001000
adc VAR WORD
adcbyte VAR BYTE
SPEED VAR WORD
SPEEDbyte VAR BYTE
SWITCH VAR PORTC.4
main:
IF SWITCH = 1 THEN
ADCIN 0, adc
adcbyte = adc/140
ADCIN 1, SPEED
SPEEDbyte = SPEED/140
PORTB = %00000001 << adcbyte
PAUSE 100*SPEEDbyte
PORTB = 0
PAUSE 100*SPEEDbyte
ELSE
ADCIN 0, adc
adcbyte = adc/140
PORTB = %00000001 << adcbyte
ENDIF
GOTO main

Giulio Castorina Says: 24.02.10 at 4:48 am
Hi there,
very interesting…looking forward to see more!
Have you some good book suggestions about physical computing devices?
Cheers,
Giulio
crtl-i Says: 24.02.10 at 6:26 am
There’s a book called “Physical Computing,” which I sometimes look at. Most of the useful information is on the web I think.