Im testing out the Adafruit 1188 capacitive touch breakout and it comes with example code. In this code they use bitwise shift left to cycle thru the array of touch pads and print out the pad number when it's touched:
for (uint8_t i=0; i<8; i++) {
if (touched & (1 << i)) {
Serial.print("C"); Serial.print(i+1); Serial.print("\t");
}
}
Could anyone explain how this works?
Im familiar with cycling thru an array of buttons in this way:
for(i = 0; i<8, i++) {
if (button[i] = LOW) {
// do something
}
}
This gives me the option to write specific functions for the different buttons in the array because im using the if (button[ i ] = LOW) to know exactly which button in the array was pressed. How would i be able to know which pad is pressed using the bitshifting method so that i can write functions for each pad when it's touched? Any help would be greatly appreciated!