Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int write_pins[] = { 0,1,2,3,4,5,6 };
- long max_min_array[16][2];
- int max_min(int pin,int value){
- //-------------------------------------------
- // set to initial reads and then move min_max
- // if value > min
- // if value < max
- //-------------------------------------------
- //Serial.println("inside max_min");
- //Serial.println(pin);
- int MIN = max_min_array[pin][0];
- int MAX = max_min_array[pin][1];
- if ( ( MIN && MAX ) == 0 ){
- max_min_array[pin][0] = value;
- max_min_array[pin][1] = value;
- return 0;
- }
- // min
- if ( MIN > value ){
- max_min_array[pin][0] = value;
- return 1;
- }
- // max
- if ( MAX < value ){
- max_min_array[pin][1] = value;
- return 2;
- }
- return 3;
- }
- int mux_pin_select(int mux_pin){
- //-------------------------------------------
- //Serial.println("inside mux_pin_select");
- // sets select pins based on pin (pin = decimal)
- // write_pins 0,1 = empty
- // write_pins 2 = Disable
- // write_pins 3,4,5,6 = S0,S1,S2,S3
- //-------------------------------------------
- int select_pin_map[] = { 3,4,5,6 };
- //Serial.println(mux_pin);
- for ( int b = 0; b < 4;b++){
- int bitset = bitRead(mux_pin, b);
- //Serial.print(bitset);
- digitalWrite(select_pin_map[b], bitset);
- }
- //Serial.println("");
- return 0;
- }
- int multiplex_read(){
- //-------------------------------------------
- // For mux_pin select pin "mux_pin_select()", read A0, and
- // store "max_min(mux_pin,sensorValue)"
- //-------------------------------------------
- //Serial.println("inside multiplex read");
- //Serial.println("##### select pins #####");
- for (int mux_pin = 0; mux_pin <= 15; mux_pin++){
- mux_pin_select(mux_pin);
- long sensorValue = analogRead(A0);
- for (int i = 0; i < 5; i++){
- sensorValue = analogRead(A0) + sensorValue;
- }
- sensorValue = sensorValue/5;
- int result = max_min(mux_pin,sensorValue);
- /*
- Serial.print("sensorValue: ");
- Serial.print(sensorValue);
- Serial.print(" max_min_return: ");
- Serial.print(result);
- if (result == 0){
- Serial.println(" Initial Value Added");
- }
- if (result == 1){
- Serial.println(" Minimum Value Added");
- }
- if (result == 2){
- Serial.println(" Maximum Value Added");
- }
- if (result == 3){
- Serial.println(" No Value Added");
- }
- */
- }
- return 0;
- }
- void setup(){
- // clear max_min_array and multiplex_read_array
- for ( int i = 0; i <= 15; i++){
- max_min_array[i][0] = 0;
- max_min_array[i][1] = 0;
- }
- // initialize write pins
- for ( int i = 0; i <= 7; i++){
- pinMode(write_pins[i], OUTPUT);
- }
- Serial.begin(115200);
- Serial.println("\nInitializing Serial.\nInput Alphanumeric and Press Enter/Send.");
- }
- void loop(){
- if ( Serial.available()){
- Serial.println("\nStarting multiplex_read().");
- while (true){
- for ( int i = 0; i <= 250; i++){ // approx 4 seconds with the current code
- multiplex_read();
- }
- Serial.println("### Min Max Array #########");
- for (int i = 0; i <= 15; i++){
- Serial.print("\n### Row/Mux: ");
- Serial.println(i);
- for (int j = 0; j <= 1; j++){
- Serial.print(max_min_array[i][j]);
- Serial.print(" ");
- }
- }
- }
- }
- }
- ##################
- output
- ###################
- ### Min Max Array #########
- ### Row: 0
- 365 375
- ### Row: 1
- 441 458
- ### Row: 2
- 231 248
- ### Row: 3
- 420 432
- ### Row: 4
- 335 369
- ### Row: 5
- 0 0
- ### Row: 6
- 0 0
- ### Row: 7
- 0 0
- ### Row: 8
- 0 0
- ### Row: 9
- 0 0
- ### Row: 10
- 0 0
- ### Row: 11
- 0 0
- ### Row: 12
- 0 0
- ### Row: 13
- 0 0
- ### Row: 14
- 0 0
- ### Row: 15
- 0 0 ### Min Max Array #########
- ### Row: 0
- 365 1096
- ### Row: 1
- 441 460
- ### Row: 2
- 231 260
- ### Row: 3
- 418 432
- ### Row: 4
- 335 376
- ### Row: 5
- 0 0
- ### Row: 6
- 0 0
- ### Row: 7
- 0 0
- ### Row: 8
- 0 0
- ### Row: 9
- 0 0
- ### Row: 10
- 0 0
- ### Row: 11
- 0 0
- ### Row: 12
- 0 0
- ### Row: 13
- 0 0
- ### Row: 14
- 0 0
- ### Row: 15
- 0 0 ### Min Max Array #########
- ### Row: 0
- 290 1096
- ### Row: 1
- 194 1078
- ### Row: 2
- 231 272
- ### Row: 3
- 409 432
- ### Row: 4
- 335 376
- ### Row: 5
- 0 0
- ### Row: 6
- 0 0
- ### Row: 7
- 0 0
- ### Row: 8
- 0 0
- ### Row: 9
- 0 0
- ### Row: 10
- 0 0
- ### Row: 11
- 0 0
- ### Row: 12
- 0 0
- ### Row: 13
- 0 0
- ### Row: 14
- 0 0
- ### Row: 15
- 0 0 ### Min Max Array #########
- ### Row: 0
- 290 1096
- ### Row: 1
- 194 1078
- ### Row: 2
- 231 1043
- ### Row: 3
- 406 432
- ### Row: 4
- 335 379
- ### Row: 5
- 0 0
- ### Row: 6
- 0 0
- ### Row: 7
- 0 0
- ### Row: 8
- 0 0
- ### Row: 9
- 0 0
- ### Row: 10
- 0 0
- ### Row: 11
- 0 0
- ### Row: 12
- 0 0
- ### Row: 13
- 0 0
- ### Row: 14
- 0 0
- ### Row: 15
- 0 0 ### Min Max Array #########
- ### Row: 0
- 290 1096
- ### Row: 1
- 194 1078
- ### Row: 2
- 109 1043
- ### Row: 3
- 356 1020
- ### Row: 4
- 335 379
- ### Row: 5
- 0 0
- ### Row: 6
- 0 0
- ### Row: 7
- 0 0
- ### Row: 8
- 0 0
- ### Row: 9
- 0 0
- ### Row: 10
- 0 0
- ### Row: 11
- 0 0
- ### Row: 12
- 0 0
- ### Row: 13
- 0 0
- ### Row: 14
- 0 0
- ### Row: 15
- 0 0 ### Min Max Array #########
- ### Row: 0
- 290 1096
- ### Row: 1
- 194 1078
- ### Row: 2
- 109 1043
- ### Row: 3
- 317 1020
- ### Row: 4
- 286 1068
- ### Row: 5
- 0 0
- ### Row: 6
- 0 0
- ### Row: 7
- 0 0
- ### Row: 8
- 0 0
- ### Row: 9
- 0 0
- ### Row: 10
- 0 0
- ### Row: 11
- 0 0
- ### Row: 12
- 0 0
- ### Row: 13
- 0 0
- ### Row: 14
- 0 0
Advertisement
Add Comment
Please, Sign In to add comment