Go Down

Topic: Code for analog-to-digital initialisation (Read 1 time) previous topic - next topic

wizzkid

Hello!
I have a few questions!

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:


Code: [Select]
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);
}


Thanks in advance!

robtillaart

Quote
And how do you use ArduinoDue pin A0 that reads the value for the buttons on the LCD-shield.
I understand the words individually but not what you are asking for?

Sounds like a school project?
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

KenF

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. 

Code: [Select]

//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;
}

wizzkid

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.

KenF

So it's not the buttons on the LCD shield that interests you?

wizzkid

No I am interested, but first I need to initialize the A/D-converter and I dont know how to do that i C-programming

KenF

No I am interested, but first I need to initialize the A/D-converter
Whoever told you that, should also tell you how.

Robin2

To the best of my knowledge reading from the ADC involves


Code: [Select]
myData = analogRead(analogPin);

and nothing else

If you need to read from different pins you should discard the first reading after changing to a different pin.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up