Hi,
I would to save the portname in an array for use with a "for" istruction (I use it, for read the configured pinmode from the eeprom).
I'v tryed creating a byte array wich contains the ports name:
const byte ANALOG_PINS[ANALOG_NR_PINS] = {
A0,A1,A2,A3,A4,A5 };
const byte DIGITAL_PINS[DIGITAL_NR_PINS] = {
6,7,8,9};
But it works well for the Digital Pins, and give a weird output for the Analog Pins.
It is the serial output:
Reading configuration...
D6 INPUT - State: 0
D7 INPUT - State: 0
D8 INPUT - State: 0
D9 INPUT - State: 0
INPUT - State: 0
INPUT - State: 0
INPUT - State: 0
INPUT - State: 0
INPUT - State: 0
INPUT - State: 0
How may I can get the portname A0,A1 for Analogs pins... ?
I'v tryed with somethings like:
String tmp = ANALOG_PINS[i];
Serial.println(ANALOG_PINS[i]);
But it didnt work too.
Someone may help me ?
Thank you,
Best Regards
Full code:
#include <EEPROM.h>
/* Set how many pin we have, and their name */
const byte ANALOG_NR_PINS = 6;
const byte DIGITAL_NR_PINS = 4;
const byte ANALOG_PINS[ANALOG_NR_PINS] = {
A0,A1,A2,A3,A4,A5 };
const byte DIGITAL_PINS[DIGITAL_NR_PINS] = {
6,7,8,9};
void setup()
{
Serial.begin(9600);
Serial.println("Reading configuration... ");
for (int i = 0; i <= DIGITAL_NR_PINS-1; i++) {
int conf = EEPROM.read(i+6);
int val = digitalRead(DIGITAL_PINS[i]);
Serial.print("D");
Serial.print(DIGITAL_PINS[i], DEC);
Serial.print("\t");
switch (conf) {
case 0:
Serial.print("INPUT - State: ");
Serial.println(val);
pinMode (DIGITAL_PINS[i], INPUT);
break;
case 1:
Serial.print("OUTPUT - State: ");
Serial.println(val);
pinMode (DIGITAL_PINS[i], OUTPUT);
break;
default:
Serial.print("INVALID VALUE - NOT CONFIGURED: ");
Serial.print(conf);
Serial.println(val);
}
}
for (int i = 0; i <= ANALOG_NR_PINS-1; i++) {
int conf = EEPROM.read(i);
int val = digitalRead(ANALOG_PINS[i]);
Serial.print(ANALOG_PINS[i]);
Serial.print("\t");
switch (conf) {
case 0:
Serial.print("INPUT - State: ");
Serial.println(val);
pinMode (ANALOG_PINS[i], INPUT);
break;
case 1:
Serial.print("OUTPUT - State: ");
Serial.println(val);
pinMode (ANALOG_PINS[i], OUTPUT);
break;
default:
Serial.print("INVALID VALUE - NOT CONFIGURED: ");
Serial.println(val);
}
}
}
void loop()
{
// idling...
}