Created
September 18, 2021 16:32
-
-
Save GluTbl/2cd0be57e506effb716dfc5a6003efec to your computer and use it in GitHub Desktop.
[GPIO arduino test] #arduino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//For digital pins | |
#define DIGITAL_PIN_COUNT 12 | |
char *digital_pins[] = {"D0", "D1", "D2" , "D3" , "D4" , "D5", "D6", "D7", "D8", "D9", "D10", "D11", "D12", "D13"}; | |
int *valid_digital_pins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13}; | |
//////////////////////// | |
//For Aanlogue pin | |
#define ANALOG_PIN_COUNT 6 | |
char *analog_pins[] = {"A0", "A1", "A2", "A3", "A4", "A5"}; | |
int *valid_analog_pins[] = {A0, A1, A2, A3, A4, A5,}; | |
void setup() { | |
Serial.begin(9600); | |
for (int i = 0; i < DIGITAL_PIN_COUNT/**Hard coded**/; i++) { | |
int pin_value = valid_digital_pins[i]; | |
pinMode(pin_value, INPUT); | |
digitalWrite(pin_value, HIGH); //use internal pullup | |
Serial.println(digital_pins[pin_value]); | |
} | |
for (int i = 0; i < ANALOG_PIN_COUNT/**Hard coded**/; i++) { | |
int pin_value = valid_analog_pins[i]; | |
pinMode(pin_value, INPUT_PULLUP);//use pullup resistor | |
Serial.println(analog_pins[i]); | |
} | |
} | |
void check_digital_pins() { | |
for (int i = 0; i < DIGITAL_PIN_COUNT/**Hard coded**/; i++) { | |
int pin_value = valid_digital_pins[i]; | |
bool value = digitalRead(pin_value); | |
Serial.print(digital_pins[pin_value]); | |
Serial.print("="); | |
if (value) { | |
Serial.print("1, "); | |
} else { | |
Serial.print("0, "); | |
} | |
} | |
Serial.println(""); | |
} | |
void check_analog_pins() { | |
for (int i = 0; i < ANALOG_PIN_COUNT/**Hard coded**/; i++) { | |
int pin_value = valid_analog_pins[i]; | |
int value = analogRead(pin_value); | |
Serial.print(analog_pins[i]); | |
Serial.print("="); | |
Serial.print(value); | |
Serial.print(" , "); | |
} | |
Serial.println(""); | |
} | |
void loop() { | |
// put your main code here, to run repeatedly: | |
check_digital_pins(); | |
// check_analog_pins(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment