I would like to know how to program an Arduino mega board if I want multiple inputs and outputs. Here I have programmed the circuit with only a single input and output:
As your coding gets stronger, you'll learn to do this with an array of pin identifiers for input and output(the following works on a Nano). Then madmark's code could become something like:
int inarray[] = {1, 2, 3};
int outarray[] = {4, 5, 6};
int dioarraylen = 3;
int i;
void setup() {
// put your setup code here, to run once:
for (i = 0; i < dioarraylen; i++) {
pinMode(inarray[i], INPUT_PULLUP);
pinMode(outarray[i], OUTPUT);
}
}
void loop() {
int t;
for (i = 0; i < dioarraylen; i++) {
digitalWrite(outarray[i], !digitalRead(inarray[i]));
}
}