コード例 #1
0
bool TSL2561_I2C::isPowerEnabled(){
    char control = readSingleRegister( TSL_CONTROL );
    bool power = 0;
    if( control == 3 ){
        power = 1;
    }
    return power;
}
コード例 #2
0
int TSL2561_I2C::readGain(){
    char timing = readSingleRegister( TSL_TIMING );
    char gain_bit = ( timing << 3 ) >> 7; // keep only bit 4
    int gain;
    switch (gain_bit) {
        case 0:
            gain = 1;
            break;
        case 1:
            gain = 16;
            break;
        default:
            gain = 0;
            break;
    }
    return gain;
}
コード例 #3
0
float TSL2561_I2C::readIntegrationTime(){
    char timing = readSingleRegister( TSL_TIMING );
    char integ = ( timing << 6 ) >> 6; // keep bits 0 & 1
    int itime;
    switch (integ) {
        case 0:
            itime = 13.7;
            break;
        case 1:
            itime = 101;
            break;
        case 2:
            itime = 402;
            break;
        default:
            itime = 0;
            break;
    }
    return itime;
}
コード例 #4
0
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;
}
コード例 #5
0
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;
}
コード例 #6
0
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);
}
コード例 #7
0
int TSL2561_I2C::getRevisionNumber(){
    char id = readSingleRegister( TSL_ID );
    char revno = ( id << 4 ) >> 4; // keep lower 4 bits
    return (int)revno;
}
コード例 #8
0
int TSL2561_I2C::getPartNumber(){
    char id = readSingleRegister( TSL_ID );
    char partno = id >> 4; // keep upper 4 bits
    return (int)partno;
}
コード例 #9
0
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;
}
コード例 #10
0
int TSL2561_I2C::readInterruptControl(){
    char interrupt = readSingleRegister( TSL_INTERRUPT );
    char control = ( interrupt << 2 ) >> 6; // keep only bits 4 & 5 
    return (int)control;
}
コード例 #11
0
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;
}
コード例 #12
0
int TSL2561_I2C::readInterruptPersistence(){
    char interrupt = readSingleRegister( TSL_INTERRUPT );
    char persist = ( interrupt << 4 ) >> 4; // discard bits 4 to 7, keep only bits 0 to 3 
    return (int)persist;
}