Tuesday, December 11, 2007

Final | coding and mapping

Our next step should be checking which switch connect to which pin. Arduino got some values from the switches (from value 0 to value 63), but we could not know that they are from which switches. So we started checking through each switch and matched the value and the switch. Actually, for some reasons, our first mapping did not work, so we did twice. It was really time consuming. But after this work, we faced another issue. We should know two things - the positions of the switches and switches' status, turn on or turn off. So we started rewriting our code. We tried to say that an array is saying the positions of switches and if this array's value is 0 (or 1) that means switches are off(or on). But we did not get it with this logic. The logic was perfect but it was hard to translate to the code for us. So, we went back to the start point and restarted. That point, I got an idea. We have 64 arraies and they can have two valuses which are 0 and 1. For example, if position #10 switch is on, val[9] will have 1. Instead of an arduino reads array positions and values (0 or 1) saperately, what if an arduino reads one value at once? I thought I could make it with a simple math.

if((channelNum+1) * val[channelNum] == channelNum+1){
Serial.print(((64+(channelNum+1))),BYTE);
Serial.print("\t");
//switch on
}

if( (channelNum+1) + val[channelNum] == channelNum+1){
Serial.print((channelNum+1),BYTE);
Serial.print("\t");
//switch off

So if switches are on, an arduino will send switch number(1-64) and if they are off , it will send switch number+64 to processing. Finally, processing could get unique values accoding to the switch's status so it could trigger unique images.

No comments: