using the code example of the HT HP I tried the following program of the HT Touch Mux, but I get faulty readings for touch sensors 3+4 (1 + 2 work correctly).
If I press Touch3 it shows 2+3+4 pressed
If I press Touch 4 it shows nothing pressed.
What's wrong?
Is there already a HTTouchMux Sensor predefined?
Code: Select all
#define printf1( _x, _y, _format1, _value1) { \
string sval1 = FormatNum(_format1, _value1); \
TextOut(_x, _y, sval1); \
}
int switches, switch1, switch2, switch3, switch4, value;
task main(){
SetSensorType(S2, SENSOR_TYPE_TOUCH);
SetSensorMode(S2, SENSOR_MODE_RAW);
while (true) {
value=1023-SensorRaw(S2);
switches=339*value;
switches/=1023-value;
switches+=5;
switches/=10;
if(switches&8) switch4=1; else switch4=0;
if(switches&4) switch3=1; else switch3=0;
if(switches&2) switch2=1; else switch2=0;
if(switches&1) switch1=1; else switch1=0;
printf1(0,56, "raw-val= %4d", value);
printf1(0,48, "switches=%4d", switches);
printf1(0,40, "switch1= %4d", switch1);
printf1(0,32, "switch2= %4d", switch2);
printf1(0,24, "switch3= %4d", switch3);
printf1(0,16, "switch4= %4d", switch4);
Wait(10);
}
}