There are currently 0 users and 3 guests online.
C++ Library for $50 robot Version 2
Submitted by Webbot on January 1, 2009 - 10:55pm.
This class handles analogue to digital input pins.To create a new input pin using channel 4 (ADC4) just use:
You can then read an 8 bit value via:
unsigned char value = myIn.ReadByte();
or a 10 bit value via:
unsigned short value = myIn.ReadShort();
Notice that you DON'T need to initialise the A2D convertor at all. Look at the file you will see the Init method that, by default, is called with some default values. If you want to use other values then you can call this Init method yourself BEFORE you create any A2D inputs. Since this is a static method it can be done by writing:
A2D.Init(ADC_PRESCALE.ADC_PRESCALE_DIV32, ADC_REFERENCE. ADC_REFERENCE_AVCC);
If you need to save power and turn off the A2D function then call:
You can turn it back on later by calling A2D.Init again.