Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************************************************************************
- Mux_Analog_Input_2D_Input
- Multiplexer Analog 2D Input
- July 19, 2019
- This software is meant for use in the Rineke imager system, a 64-pixel
- experimental photodiode imager.
- Hardware Hookup:
- Mux Breakout ----------- Arduino
- ROW_A ------------------- 0
- ROW_B ------------------- 1
- ROW_C ------------------- 2
- COL_A ------------------- 3
- COL_B ------------------- 4
- COL_C ------------------- 5
- SIGNAL_OUT ------------------- A0
- VCC ------------------- 5V
- GND ------------------- GND
- Development environment specifics:
- Arduino 1.8.9
- ******************************************************************************/
- /////////////////////
- // Pin Definitions //
- /////////////////////
- const int selectRowPins[3] = {0, 1, 2}; // ROW_A-->0, ROW_B-->1, ROW_C-->2
- const int selectColPins[3] = {3, 4, 5}; // COL_A-->3, COL_B-->4, COL_C-->5
- const int SIGNAL_OUT = A0; // SIGNAL_OUT-->A0
- void setup()
- {
- Serial.begin(9600); // Initialize the serial port at 9600 baud
- // Set up the select pins as outputs and sets
- for (int i=0; i<3; i++)
- {
- pinMode(selectRowPins[i], OUTPUT);
- digitalWrite(selectRowPins[i], LOW);
- }
- for (int i=0; i<3; i++)
- {
- pinMode(selectColPins[i], OUTPUT);
- digitalWrite(selectColPins[i], LOW);
- }
- pinMode(SIGNAL_OUT, INPUT); // Set up SIGNAL_OUT as an input
- }
- void loop()
- {
- // Loop through all eight pins.
- for (byte rowPin=0; rowPin<=7; rowPin++)
- {
- selectRowPin(rowPin); // Select one at a time
- for (byte colPin=0; colPin<=7; colPin++)
- {
- selectColPin(colPin); // Select one at a time
- int inputValue = analogRead(A0); // and read SIGNAL_OUT
- Serial.print(String(inputValue) + " ");
- // delayMicroseconds(1600);
- }
- }
- Serial.println(); // Add a line break after each array
- Serial.println(); // Add a line break after each array
- }
- // The selectRowPin function sets the ROW_A, ROW_B, and R0W_C pins
- // accordingly, given a pin from 0-7.
- void selectRowPin(byte pin)
- {
- if (pin > 7) return; // Exit if pin is out of scope
- for (int i=0; i<3; i++)
- {
- if (pin & (1<<i))
- digitalWrite(selectRowPins[i], HIGH);
- else
- digitalWrite(selectRowPins[i], LOW);
- }
- }
- void selectColPin(byte pin)
- {
- if (pin > 7) return; // Exit if pin is out of scope
- for (int i=0; i<3; i++)
- {
- if (pin & (1<<i))
- digitalWrite(selectColPins[i], HIGH);
- else
- digitalWrite(selectColPins[i], LOW);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement