11. Pseudo Codes Examples
Control Registers
// The Control Register defines the operating modes and gain settings of the ALS of LTR-329.
// Default settings is 0x00 (in Standby mode).
Slave_Addr = 0x29 // Slave address of LTR-329 device
// Enable ALS
Register_Addr = 0x80 // ALS_CONTR register
Command = 0x01 // For Gain X1
// For Gain X96, Command = 0x1D
WriteByte(Slave_Addr, Register_Addr, Command)
ALS Measurement Rate
// The ALS_MEAS_RATE register controls the ALS integration time and measurement rate.
// Default setting of the register is 0x03 (integration time 100ms, repeat rate 500ms)
Slave_Addr = 0x29 // Slave address of LTR-329 device
// Set ALS Integration Time 200ms, Repeat Rate 200ms
Register_Addr = 0x85 // ALS_MEAS_RATE register
Command = 0x12 // Int time = 200ms, Meas rate = 200ms
// For Int time = 400ms, Meas rate = 500ms, Command = 0x1B
WriteByte(Slave_Addr, Register_Addr, Command)
ALS Data Registers (Read Only)
// The ALS Data Registers contain the ADC output data for the respective channel.
// These registers should be read as a group, with the lower address being read first.
Slave_Addr = 0x29 // Slave address of LTR-329 device
// Read back ALS_DATA_CH1
Register_Addr = 0x88 // ALS_DATA_CH1 low byte address
ReadByte(Slave_Addr, Register_Addr, Data0)
Register_Addr = 0x89 // ALS_DATA_CH1 high byte address
ReadByte(Slave_Addr, Register_Addr, Data1)
// Read back ALS_DATA_CH0
Register_Addr = 0x8A // ALS_DATA_CH0 low byte address
ReadByte(Slave_Addr, Register_Addr, Data2)
Register_Addr = 0x8B // ALS_DATA_CH0 high byte address
ReadByte(Slave_Addr, Register_Addr, Data3)
ALS_CH1_ADC_Data = (Data1 << 8) | Data0 // Combining lower and upper bytes to give 16-bit Ch1 data
ALS_CH0_ADC_Data = (Data3 << 8) | Data2 // Combining lower and upper bytes to give 16-bit Ch0 data