Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * @brief Starts the sensing of how many lumens there are.
- * @details Requests the sensor to retriever how many lumens there are
- * based on how long it is sensing, with shorter sensing durations being
- * able to read smaller lumens levels but cutting off at a lower lumen amount.
- * If there is a maximum light level for the interval try sensing at a larger
- * amount to see the non chipped off higher lumen input.
- *
- * @param time 400, 200, or 100. Units are in milliseconds.
- */
- void Lumen_Sensor::start_continous_conversion(uint8_t time){
- // First set the timing interval.
- // Ask for access to the Lumen sensor
- Wire.beginTransmission(this->address);
- // We will be working with the Control Register(0x00).
- // Command bit = 1
- // 6:4 = 0
- // 3:0 = Config Register (0x01)
- Wire.write((1 << 7) | 0x01);
- // Set to continous conversion.
- // 0b00 = 400 milliseconds, 1x multiplier.
- // 0b01 = 200 milliseconds, 2x multiplier.
- // 0b10 = 100 milliseconds, 4x multiplier.
- // 0b11 = Reserved
- uint8_t TCNTRL;
- if (time == 400)
- TCNTRL = 0b00;
- else if (time == 200)
- TCNTRL = 0b01;
- else if (time == 100)
- TCNTRL = 0b10;
- else
- TCNTRL = 0b00;
- Wire.write(0x00 | TCNTRL);
- // End transmission.
- Wire.endTransmission();
- // And now we start the continous conversion!
- // Ask for access to the Lumen sensor
- Wire.beginTransmission(this->address);
- // We will be working with the Control Register(0x00).
- // Command bit = 1
- // 6:4 = 0
- // 3:0 = Control Register (0x00)
- Wire.write((1 << 7) | 0x00);
- // Set to continous conversion(Normal Operation)
- // 0b00 = Power down.
- // 0b01 = Reserved.
- // 0b10 = Run a single ADC cycle and return to PowerDown.
- // 0b11 = Normal operation.
- Wire.write(0x00 | 0b11);
- // End transmission.
- Wire.endTransmission();
- }
- /**
- * @brief Displays the contents of each register via the serial bus.
- * @details The last byte is the device ID register, shift it to the right
- * four positions to check what device you have if you can't do it via
- * get_device_id().
- */
- void Lumen_Sensor::display_all_registers(void){
- // This is split up like this because the address auto incrementation on the
- // IC does not seem to work or I don't know how to get it to work correctly.
- // Will hold the contents of the device.
- uint8_t data[10];
- // Ask for access to the Lumen sensor
- Wire.beginTransmission(0x29);
- // Command bit = 1
- // 6:4 = 0
- // 3:0 = Register address(0x00)
- Wire.write(1 << 7);
- // End transmission.
- Wire.endTransmission();
- // Request a byte from device 0x29 (lumen meter).
- Wire.requestFrom(0x29, 0x01);
- // Get the return data.
- data[0] = Wire.read();
- //==========
- // Ask for access to the Lumen sensor
- Wire.beginTransmission(0x29);
- // Command bit = 1
- // 6:4 = 0
- // 3:0 = Register address(0x00)
- Wire.write((1 << 7) | 0x01);
- // End transmission.
- Wire.endTransmission();
- // Request a byte from device 0x29 (lumen meter).
- Wire.requestFrom(0x29, 0x01);
- // Get the return data.
- data[1] = Wire.read();
- //==========
- // Ask for access to the Lumen sensor
- Wire.beginTransmission(0x29);
- // Command bit = 1
- // 6:4 = 0
- // 3:0 = Register address(0x00)
- Wire.write((1 << 7) | 0x04);
- // End transmission.
- Wire.endTransmission();
- // Request a byte from device 0x29 (lumen meter).
- Wire.requestFrom(0x29, 0x01);
- // Get the return data.
- data[2] = Wire.read();
- //==========
- // Ask for access to the Lumen sensor
- Wire.beginTransmission(0x29);
- // Command bit = 1
- // 6:4 = 0
- // 3:0 = Register address(0x00)
- Wire.write((1 << 7) | 0x05);
- // End transmission.
- Wire.endTransmission();
- // Request a byte from device 0x29 (lumen meter).
- Wire.requestFrom(0x29, 0x01);
- // Get the return data.
- data[3] = Wire.read();
- //==========
- // Ask for access to the Lumen sensor
- Wire.beginTransmission(0x29);
- // Command bit = 1
- // 6:4 = 0
- // 3:0 = Register address(0x00)
- Wire.write((1 << 7) | 0x0A);
- // End transmission.
- Wire.endTransmission();
- // Request a byte from device 0x29 (lumen meter).
- Wire.requestFrom(0x29, 0x01);
- // Get the return data.
- data[4] = Wire.read();
- // And now we display it all to the serial port.
- Serial.println("TSL45315 registers: ");
- Serial.print(" CONTROL(0x00): ");
- Serial.println(data[0]);
- Serial.print(" CONFIG(0x01): ");
- Serial.println(data[1]);
- Serial.print(" DATALOW(0x04): ");
- Serial.println(data[2]);
- Serial.print(" DATAHIGH(0x05): ");
- Serial.println(data[3]);
- Serial.print(" Device_ID(0x0A): ");
- Serial.print(data[4], HEX);
- Serial.print(" or when converted: ");
- Serial.println(data[4] >> 4, HEX);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement