Peripheral myC As ColorRGB @ 0 ' Set the module ID as 0 Dim g_wC, g_wR, g_wG, g_wB As Word ' Set the parameters for storing the sensed values Sub Main() Dim bStatus As Byte ' Set the parameters for storing the status values Dim cTemp As Byte ' Set the characters for temporary storage Debug CLS, "Turn on the red light" myC.SetLEDRGB(20, 0, 0) ' Set the module to turn on only the red light of the LED myC.TurnOnLED() ' Turn on the LED Pause 3000 ' Pause for three seconds myC.TurnOffLED() ' Turn off the LED Debug CLS, "Turn on the green light" myC.SetLEDRGB(0, 20, 0) ' Set the module to turn on only the green light of the LED myC.TurnOnLED() ' Turn on the LED Pause 3000 ' Pause for three seconds myC.TurnOffLED() ' Turn off the LED Debug CLS, "Turn on the blue light" myC.SetLEDRGB(0, 0, 20) ' Set the module to turn on only the blue light of the LED myC.TurnOnLED() ' Turn on the LED Pause 3000 ' Pause for three seconds myC.TurnOffLED() ' Turn off the LED Debug CLS myC.LoadLED() ' Adjust the light intensity of the LED as the default value myC.SetPeriod(0) ' Set the measurement time myC.SetGain(0) ' Set the measurement scaling factor myC.SetPrescalar(0) ' Set the measurement prescaling factor myC.DisValReadyEvent() ' Disable the notification event for the update of the sensing value. myC.StartMeasure() ' Start measuring the color values '---------------------------------------------------------------------------- ' The Do Loop continues the measurement until the status value is detected. '---------------------------------------------------------------------------- Do bStatus = myC.GetCRGB(g_wC, g_wR, g_wG, g_wB) ' Read the sensed color values Loop Until bStatus=1 Debug "C: ", %DEC5R g_wC, CR ' Display the total light intensity Debug "R: ", %DEC5R g_wR, CR ' Display the value of the red color Debug "G: ", %DEC5R g_wG, CR ' Display the value of the green color Debug "B: ", %DEC5R g_wB, CR ' Display the value of the blue color Debugin "Enter any value to start the repeated measurement", %CHR cTemp Debug CSRXY(1, 5), CLREOL myC.EnValReadyEvent() ' Enable the notification event for the update of the sensing value. myC.StartMeasure() ' Start measuring the color values Do Debug CSRXY(4, 1), %DEC5R g_wC ' Display the total light intensity Debug CSRXY(4, 1), %DEC5R g_wR ' Display the value of the red color Debug CSRXY(4, 1), %DEC5R g_wG ' Display the value of the green color Debug CSRXY(4, 1), %DEC5R g_wB ' Display the value of the blue color Loop End Sub Event myC.ValReadyEvent() myC.GetClear(g_wC) ' Get the total light intensity myC.GetRed(g_wR) ' Get the value of the red color myC.GetGreen(g_wG) ' Get the value of the green color myC.GetBlue(g_wB) ' Get the value of the blue color myC.StartMeasure() ' Start measuring the color values End Event