SHARE
TWEET

Untitled

a guest Jun 19th, 2019 75 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Pin Definitions
  2. const int selectPins[3] = {2, 3, 4}; // S0~2, S1~3, S2~4
  3. const int zInput = A0; // Connect common (Z) to A0 (analog input)
  4.  
  5. void setup() {
  6.   Serial.begin(38400); // Initialize the serial port
  7.   // Set up the select pins as outputs:
  8.   for (int i=0; i<3; i++)
  9.   {
  10.     pinMode(selectPins[i], OUTPUT);
  11.     digitalWrite(selectPins[i], HIGH);
  12.   }
  13.   pinMode(zInput, INPUT);
  14. }
  15.  
  16. void loop()
  17. {
  18.   // Loop through all eight pins.
  19.   for (byte pin=0; pin<=7; pin++){
  20.    
  21.     for (int i=0; i<3; i++){
  22.       if (pin & (1<<i))
  23.         digitalWrite(selectPins[i], HIGH);
  24.       else
  25.         digitalWrite(selectPins[i], LOW);
  26.     }
  27.    
  28.     int inputValue = analogRead(A0);
  29.     Serial.print(String(inputValue) + "\t");
  30.   }
  31.  
  32.   Serial.println();
  33. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top