int TSL2561_I2C::setGain( const int gain ){ char timing_old = readSingleRegister( TSL_TIMING ); char timing_new = 0; int ack = 0; switch (gain){ case 1: timing_new = timing_old & 239; // sets bit 4 to 0 break; case 16: timing_new = timing_old | 16; // sets bit 4 to 1 break; default: ack = 2; // 2 used to indicate invalid entry break; } if ( ack != 2 ){ ack = writeSingleRegister( TSL_TIMING, timing_new ); } return ack; }
int TSL2561_I2C::setIntegrationTime( const float itime ){ char timing_old = readSingleRegister( TSL_TIMING ); char timing_new = 0; int ack = 0; if( abs( itime - 13.7 ) <= 0.001 ){ timing_new = timing_old & 252; // set bits 0 & 1 (INTEG) to 00 } else if( abs( itime - 101 ) <= 0.001 ){ timing_new = timing_old | 1; // sets bit 0 to 1 timing_new = timing_new & 253; // sets bit 1 to 0 } else if( abs( itime - 402 ) <= 0.001 ){ timing_new = timing_old | 3; // sets bits 0 & 1 (INTEG) to 11 } else { ack = 2; // indicates invalid entry } if ( ack != 2 ){ ack = writeSingleRegister( TSL_TIMING, timing_new ); } return ack; }
void setup() { // #if DEBUGGING Serial.begin(9600); // #endif /* Enabling I2C and IR receiver */ Wire.begin(); // irReceiver.enableIRIn(); /* Setting GPIO modes */ pinMode(13,OUTPUT); DDRB &= ~(1<<3); PORTB = (1<<3); pinMode(LeftMotorPin_B,OUTPUT); pinMode(LeftMotorPin_F,OUTPUT); pinMode(RightMotorPin_B,OUTPUT); pinMode(RightMotorPin_F,OUTPUT); /* Check the connection */ // #if DEBUGGING Serial.print("ConnectedTo(Should be H43) - "); Serial.print(readSingleRegister(0x0A)); Serial.print(readSingleRegister(0x0B)); Serial.println(readSingleRegister(0x0C)); //#endif /* Setting the value of the A register (0x00)=0x28 */ writeSingleRegister(0x00,0x28); /* Read A register (0x00). Correct value should be 0x28 */ //#if DEBUGGING Serial.print("ARegisterValue(shouldBe 0x28): "); Serial.println(readSingleRegister(0x00),HEX); //#endif /* Read B register (0x01) .Correct value should be 0x20 */ //#if DEBUGGING Serial.print("BRegisterValue(shouldBe 0x20): "); Serial.println(readSingleRegister(0x01),HEX); //#endif /* Setting the value of the Mode register (0x02)=0x00 */ writeSingleRegister(0x02,0x00); /* Read Mode register (0x02) .Correct value should be 0x00 */ //#if DEBUGGING Serial.print("ModeRegisterValue(shouldBe 0x00): "); Serial.println(readSingleRegister(0x02),HEX); //#endif //#if DEBUGGING Serial.println("The vaules printed will be as x y"); //#endif /*to show that the bot is ready*/ digitalWrite(13,1); Serial.println("Tell the above output to Zubeen"); while(digitalRead(SWITCH_PIN) != LOW); delay(1000); // attachInterrupt(RECEIVING_PIN,changeReadingDataFlag,LOW); }
int TSL2561_I2C::setInterruptControl( const int control ){ char interrupt_old = readSingleRegister( TSL_INTERRUPT ); char interrupt_new = interrupt_old | (char)( control << 4 ); // sets bits 4 and 5 (INTR) to the value of control int ack = writeSingleRegister( TSL_INTERRUPT, interrupt_new ); return ack; }
int TSL2561_I2C::setInterruptPersistence( const int persistence ){ char interrupt_old = readSingleRegister( TSL_INTERRUPT ); char interrupt_new = interrupt_old | (char)persistence; // sets bits 1 to 3 (PERSIST) to the value of persistence int ack = writeSingleRegister( TSL_INTERRUPT, interrupt_new ); return ack; }
int TSL2561_I2C::disablePower(){ int ack = writeSingleRegister( TSL_CONTROL, 0 ); return ack; }