Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement