I would like to know how you write a function that initializes a A/D-converter.
And how do you use ArduinoDue pin A0 that reads the value for the buttons on the LCD-shield.
This is the code that we are supposed to use:
void ADCSetup(int DuePinNr)
{
/* Insert table that maps the DuePinNr to ADC_CHANNEL_XX
*/
/* Shamelessly copied from the ASF Quick Start Guide */
adc_init(ADC, sysclk_get_main_hz(), 1000000, 8);
adc_configure_timing(ADC, 0, ADC_SETTLING_TIME_3, 1);
adc_set_resolution(ADC, ADC_MR_LOWRES_BITS_12);
adc_enable_channel(ADC, ADC_CHANNEL_XX);
adc_configure_trigger(ADC, ADC_TRIG_SW, 0);
}
Reading between the lines I suspect you have one of those displays with 5 buttons built in on A0. This works for me
btw, if no key is being pressed, it returns straight away it doesn't wait.
//returns 1 to 5 for button down
//returns 0 if no button down
int getButton()
{
static int adcValues[5] ={30, 150, 360, 535, 760};
int n, input;
input=analogRead(0);
for (n = 0; n < 5; n++)
if (input < adcValues[n])
return n+1;
return 0;
}
robtillaart:
I understand the words individually but not what you are asking for?
Sounds like a school project?
My question was: How do you read a value on the AD-input and write it on the LCD-display, by using pin A0 on the Due. We want to use C-programming for this.