Created
June 8, 2019 15:14
-
-
Save RyoKosaka/cac5935d894f208e4c32fe6a13e8e573 to your computer and use it in GitHub Desktop.
This file contains 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
// Pin Definitions | |
const int selectPins[3] = {2, 3, 4}; // S0~2, S1~3, S2~4 | |
const int zInput = A0; // Connect common (Z) to A0 (analog input) | |
void setup() { | |
Serial.begin(38400); // Initialize the serial port | |
// Set up the select pins as outputs: | |
for (int i=0; i<3; i++) | |
{ | |
pinMode(selectPins[i], OUTPUT); | |
digitalWrite(selectPins[i], HIGH); | |
} | |
pinMode(zInput, INPUT); | |
} | |
void loop() | |
{ | |
// Loop through all eight pins. | |
for (byte pin=0; pin<=7; pin++){ | |
for (int i=0; i<3; i++){ | |
if (pin & (1<<i)) | |
digitalWrite(selectPins[i], HIGH); | |
else | |
digitalWrite(selectPins[i], LOW); | |
} | |
int inputValue = analogRead(A0); | |
Serial.print(String(inputValue) + "\t"); | |
} | |
Serial.println(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment