Addressing 23017/4051 using I2C Serial Interface & PROGMEM


hello, i'm trying understand how use i2c port expander drive 16 leds. [font=verdana]an example[/font] of i'm trying coded this:
code: [select]

#include <wire.h>
lastledval = 0;
// setup i2c devices
wire.begin(); // start i2c interface
// initilise registers
gpio_write(ledaddress, ddrtrigger, i2cregisterconfig); // make outputs
gpio_write(ledaddress, 0, i2cregisterinput); // turn them off
dosensorscan(); // initial states

// value of threshold determins on / off point
void lookforchange(){
int ledval = 0;
int ledmask = 1;
for(int i=0; i<16; i++){
if(currentstate[i] < threshold) ledval |= ledmask; // add 1 in position of sensors under threshold
ledmask = ledmask << 1;
}
if(lastledval != ledval) { // has changed
ledmask = 1;
for(int i=0; i<16; i++){
if((ledmask & ledval) != (ledmask & lastledval)){
if((ledmask & ledval) == 0) {
// note off
controlsend(0x80, control[i], 0x00); // turn off control message
//notone(8);

}
else{
// note on
controlsend(0x90, control[i], currentstate[i]>>3); // turn on control message
//tone(8, notes[i], 20);

}
}
ledmask = ledmask << 1;
}
// update trigger leds
gpio_writebyteinverse(ledaddress, ledval, i2cregisterinput);
}
lastledval = ledval; // record current state of leds , midi notes / messages

}

from research i've learned it's called  exclusive disjunction.
quote
logical disjunction [i.e.] exclusive disjunction
the logical operation exclusive disjunction, called exclusive or (symbolized prefix operator j, or infix operators xor, eor, exor, ? or ?,  /??ks ??r/ or /?z?r/), type of logical disjunction on 2 operands results in value of true if 1 of operands has value of true.[1] simple way state "one or other not both."
put differently, exclusive disjunction logical operation on 2 logical values, typically values of 2 propositions, produces value of true in cases truth value of operands differ.
http://en.wikipedia.org/wiki/exclusive_disjunction

my question is: code snippet , quote above same?
a related post http://arduino.cc/forum/index.php/topic,103925.msg784024.html#msg784024 deals wiring , required libraries, post concerned coding of chip.
http://www.arduino.cc/en/reference/bitwise
curious thing don't see  the caret symbol ^ in code see symbols like: &, =!, <<, ==0 etc. have arduino ref docs recognize shift left, shit right, not , on, i'm little unclear on code doing. can me understand code doing.

thanks much.

that article missing few (read: all?) of actual bitwise operators.

if @ "bitwise operators" section of reference page, you'll see of them.
http://arduino.cc/it/reference/homepage

comparison , boolean operators shown well.



Arduino Forum > Using Arduino > Programming Questions > Addressing 23017/4051 using I2C Serial Interface & PROGMEM


arduino

Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial