int val[64];
int previousVal[64];
int a= 2; //address pins that all 4 multiplexers share, by daisy-chaining them
int b= 3;
int c= 4;
int d= 5;
int inputPin; //each multiplexer needs its own. we used pin numbers 6,7,8,9.
void setup() {
Serial.begin(9600);
pinMode(inputPin, INPUT);
pinMode(a,OUTPUT);
pinMode(b,OUTPUT);
pinMode(c,OUTPUT);
pinMode(d,OUTPUT);
for (int previousValNum = 0; previousValNum < style="color: rgb(153, 0, 0);">LOW;
}
}
void loop() {
for (int channelNum = 0; channelNum <>
// determine the four address pin values from the channelNum:
// mask off bit 0:
int pinOne = 1 & (channelNum % 16);
// shift value 1 bit to the right, and mask all but bit 0:
int pinTwo = 1 & ((channelNum >> 1) % 16) ;
// shift value 2 bits to the right, and mask all but bit 0:
int pinThree = 1 & ((channelNum >> 2) % 16);
// shift value 3 bits to the right, and mask all but bit 0:
int pinFour = 1 & ((channelNum >> 3) % 16);
// set the address pins:
digitalWrite(a,pinOne);
digitalWrite(b,pinTwo);
digitalWrite(c,pinThree);
digitalWrite(d,pinFour);
// read the digital input and store it in the value array:
int inputPin = (channelNum / 16) + 6;
val[channelNum] = digitalRead(inputPin);
}
boolean hasChanged = false; //so that arduino only sends one byte when something changes
for (int channelNum = 0; channelNum < style="color: rgb(255, 153, 0);">if (previousVal[channelNum] != val[channelNum]) {
if((channelNum+1) * val[channelNum] == channelNum+1){
Serial.print(((64+(channelNum+1))),BYTE);
Serial.print(“\t”);
//switch is on
}
if( (channelNum+1) + val[channelNum] == channelNum+1){
Serial.print((channelNum+1),BYTE);
Serial.print(“\t”);
//switch is off
}
previousVal[channelNum]=val[channelNum];
hasChanged = true;
}
}
}
No comments:
Post a Comment