Last night I was messing around with some stuff just for experimentation’s sake. I might use this in my Datalogger though, so I thought I would explore. I’m using the Pickit 2 to do some experiments on and learn new code. Here’s what I’ve discovered.
Using a potentiometer to trigger events:
In digital inputs, a high (1) is close to 5 volts, and a low (0) is close to ground. That’s all you get. Analog inputs are capable of many intermediate values ranging from either 0 – 255, or more depending on what chip you are using. I’m using the PIC16F690, and it has an 8-bit ADC. In this case ground will return 0×00 (0) and vdd will return 0xff (255).
#fuses intrc_io, nowdt, nobrownout, put
unsigned int adcByte;
setup_adc(adc_clock_internal); //The ADC uses a clock to work
setup_adc_ports(sAN0); //pin 19 ADC0
set_adc_channel(0); //This ADC0 is channel 0
while (1) //stay in this loop until reset
adcByte=read_adc(); //read_adc() return an 8-bit variable
/*I’m using the byte returned as the delay for an LED */