This unit came into being due to my wife complaining that she couldn't see the bedroom clock when the bedroom was in the dark , and she didn't want to turn the lights on to wake me. My wife didn't want a blinding light on the clock, just enough light to be able to read the time, regardless of the ambient light!

Our bedroom has a large window facing East that is almost always unshuttered, so that the bedroom light is constantly varying during the evening and morning hours. This gave me the notion that any clock illumination should be inversely proportional to the illumination within the bedroom.

This led to creation of the following simple unit, comprising a double row of 4 high brightness white LEDs, whose brightness is controlled by a PIC processor via the input from a photo diode.

The PIC was chosen as the control, as it contains an ADC input for sensing the photo diode, and a PWM channel for light intensity control of the LEDS. This unit satifactorally controls the clock illumination to the desired level.

The unit is simple to build and may have many other uses where a light source needs to be inversely proportional to the ambient light, for instance an illumination source for car instruments.

Our bedroom has a large window facing East that is almost always unshuttered, so that the bedroom light is constantly varying during the evening and morning hours. This gave me the notion that any clock illumination should be inversely proportional to the illumination within the bedroom.

This led to creation of the following simple unit, comprising a double row of 4 high brightness white LEDs, whose brightness is controlled by a PIC processor via the input from a photo diode.

The PIC was chosen as the control, as it contains an ADC input for sensing the photo diode, and a PWM channel for light intensity control of the LEDS. This unit satifactorally controls the clock illumination to the desired level.

The unit is simple to build and may have many other uses where a light source needs to be inversely proportional to the ambient light, for instance an illumination source for car instruments.

## Step 1: Components List

1 off Printed circuit board, or stripboard if you do it the simple way.

1 off power supply 15 to 18 volts AC or DC.

8 off high brightness white LEDS 5mm ( or as you wish) Led 1 - 8

1 off GP Photo diode Led 9

1 off PIC 16F684 Micro. IC1

1 Off 1 Amp bridge rectifier.

1 off 7812 12Volt regulator. IC2

1 off 78l05 5 Vlot regulator. IC3

1 off 100 uF 25 VW electrolytic capacitor.

3 off 0.01 capacitors (any small sort will suffice)

1 off 470R 1/8thw resistor R5

1 off 470K 1/8thw resistor R4

1 off 1M 1/8thw resistor R3

2 off 1R 1/8thw resistor R1-2

Wire and solder as required.

1 off power supply 15 to 18 volts AC or DC.

8 off high brightness white LEDS 5mm ( or as you wish) Led 1 - 8

1 off GP Photo diode Led 9

1 off PIC 16F684 Micro. IC1

1 Off 1 Amp bridge rectifier.

1 off 7812 12Volt regulator. IC2

1 off 78l05 5 Vlot regulator. IC3

1 off 100 uF 25 VW electrolytic capacitor.

3 off 0.01 capacitors (any small sort will suffice)

1 off 470R 1/8thw resistor R5

1 off 470K 1/8thw resistor R4

1 off 1M 1/8thw resistor R3

2 off 1R 1/8thw resistor R1-2

Wire and solder as required.

## Step 2: Circuit Board

If you are using stripboard then you will need to decide your own layout !

If you wish to make your own printed circuit board then please download the actual files in EAGLE format, or use the attached picture and process it yourself ie. copy it and use whatever pcb method you normally use to manufacture it.

If you are stuck without the facilities to make the board then as a last resort email me and I will see if I can provide you with a PCB (this is dependant on the number of requests I have for the PCBs!).

If you wish to make your own printed circuit board then please download the actual files in EAGLE format, or use the attached picture and process it yourself ie. copy it and use whatever pcb method you normally use to manufacture it.

If you are stuck without the facilities to make the board then as a last resort email me and I will see if I can provide you with a PCB (this is dependant on the number of requests I have for the PCBs!).

## Step 3: Components and PIC Programming

The components are all readily available , and should not be a problem to obtain.

Should you wish to order the PIC from me, then please request by Email and I will reply with the cost of shipping a pre-programmed PIC.

For you to self programme your own PIC 16F684 the HEX file is here available.

Carefully insert and mount all the components (following the component layout here), start with the low level components such as resistors first. Solder and trim the component legs.

Take care that the components are correctly orientated or components will be damaged. Note the LEDS have a flat side (the cathode!). The PIC should be ideally be mounted in a Dil socket and be sure that it is correctly mounted with the notch at the correct end as the layout picture. Note the polarity markings on the bridge rectifier and the Electrolytic capacitor! double check your component assembly and also the printed circuit board (for bridges/shorts or open circuits or properly soldered joints), before applying power. The circuit and PIC have been proved and tested, so of it fails to work as expected the fault is with the construction or a failed component, the most likely being that a fault exists on the copper side of the PCB, DOUBLE CHECK EVERYTHING (A visual check is the most important check you can make before any other!).

Should you wish to order the PIC from me, then please request by Email and I will reply with the cost of shipping a pre-programmed PIC.

For you to self programme your own PIC 16F684 the HEX file is here available.

Carefully insert and mount all the components (following the component layout here), start with the low level components such as resistors first. Solder and trim the component legs.

Take care that the components are correctly orientated or components will be damaged. Note the LEDS have a flat side (the cathode!). The PIC should be ideally be mounted in a Dil socket and be sure that it is correctly mounted with the notch at the correct end as the layout picture. Note the polarity markings on the bridge rectifier and the Electrolytic capacitor! double check your component assembly and also the printed circuit board (for bridges/shorts or open circuits or properly soldered joints), before applying power. The circuit and PIC have been proved and tested, so of it fails to work as expected the fault is with the construction or a failed component, the most likely being that a fault exists on the copper side of the PCB, DOUBLE CHECK EVERYTHING (A visual check is the most important check you can make before any other!).

## Step 4: Testing

Your assembly should now be ready for power up and testing.

Connect the power source to the board (15-to-18 Volts DC or AC) and expose the photo resistor to a normal bright light, the output LEDS should light up full power (Don't look directly at them, it can hurt your eyes). Next shadow the photo diode with your hand or better still with a piece of black tubing, and the output light should reduce to a very low light. If this test proves OK then you have succeeded, otherwise you need to go back to the previous section and go through the fault seeking order again.

OK your unit works, now its up to you how you use it, for my application, I mounted the board some 1 metre away from the Bedroom clock so that the clock face was evenly illuminated, and it functions very well. If you have other applications you can of course move the Photo diode away from the board via a wired connection and mount it a position better suited for your application.

Connect the power source to the board (15-to-18 Volts DC or AC) and expose the photo resistor to a normal bright light, the output LEDS should light up full power (Don't look directly at them, it can hurt your eyes). Next shadow the photo diode with your hand or better still with a piece of black tubing, and the output light should reduce to a very low light. If this test proves OK then you have succeeded, otherwise you need to go back to the previous section and go through the fault seeking order again.

OK your unit works, now its up to you how you use it, for my application, I mounted the board some 1 metre away from the Bedroom clock so that the clock face was evenly illuminated, and it functions very well. If you have other applications you can of course move the Photo diode away from the board via a wired connection and mount it a position better suited for your application.

Hey brianpxbd, <br>this is such a great idea that I decided to make this as my first instructable at all. The clock I already bought, but I would like to illuminate the clock from each of the 12 numbers each with one LED. Is your circuid board design able to also serve 4 LEDs more (two more on each line) THX!

Hi all, please note my website is changed tohttp://picdesignhouse.webplus.net/index.html and many thanks for all your interest.

Can you provide a copy of the program in assembly or C?

here it is in assembly:<br/><br/>; Assembly code generated by mikroVirtualMachine - V. 5.0.0.3<br/>; Date/Time: 09/02/2009 20:47:26<br/>; Info: <a rel="nofollow" href="http://www.mikroe.com">http://www.mikroe.com</a><br/><br/>; ADDRESS OPCODE ASM<br/>; ----------------------------------------------<br/>$0000 $28B0 GOTO _main<br/>$00D5 $ _delay_22us:<br/>;delays.pbas,17 :: sub procedure Delay_22us()<br/>;delays.pbas,18 :: Delay_us(22)<br/>$00D5 $3024 MOVLW 36<br/>$00D6 $1303 BCF STATUS, RP1<br/>$00D7 $1283 BCF STATUS, RP0<br/>$00D8 $00FA MOVWF STACK_10<br/>$00D9 $0BFA DECFSZ STACK_10, F<br/>$00DA $28D9 GOTO $-1<br/>$00DB $0000 NOP<br/>$00DC $ delays_L_3:<br/>$00DC $0008 RETURN<br/>$0085 $ _mul_16x16_u:<br/>$0085 $1303 BCF STATUS, RP1<br/>$0086 $1283 BCF STATUS, RP0<br/>;math.ppas,42 :: <br/>;math.ppas,44 :: <br/>$0087 $01FB CLRF STACK_11<br/>;math.ppas,45 :: <br/>$0088 $01FA CLRF STACK_10<br/>;math.ppas,46 :: <br/>$0089 $01F9 CLRF STACK_9<br/>;math.ppas,47 :: <br/>$008A $3080 MOVLW 128<br/>;math.ppas,48 :: <br/>$008B $00F8 MOVWF STACK_8<br/>;math.ppas,49 :: <br/>$008C $0CF1 RRF STACK_1, F<br/>;math.ppas,50 :: <br/>$008D $0CF0 RRF STACK_0, F<br/>;math.ppas,51 :: <br/>$008E $1C03 BTFSS STATUS, C<br/>;math.ppas,52 :: <br/>$008F $2899 GOTO $+10<br/>;math.ppas,53 :: <br/>$0090 $0874 MOVF STACK_4, W<br/>;math.ppas,54 :: <br/>$0091 $07F9 ADDWF STACK_9, F<br/>;math.ppas,55 :: <br/>$0092 $0875 MOVF STACK_5, W<br/>;math.ppas,56 :: <br/>$0093 $1803 BTFSC STATUS, C<br/>;math.ppas,57 :: <br/>$0094 $0F75 INCFSZ STACK_5, W<br/>;math.ppas,58 :: <br/>$0095 $07FA ADDWF STACK_10, F<br/>;math.ppas,59 :: <br/>$0096 $1803 BTFSC STATUS, C<br/>;math.ppas,60 :: <br/>$0097 $0AFB INCF STACK_11, F<br/>;math.ppas,61 :: <br/>$0098 $1003 BCF STATUS, C<br/>;math.ppas,62 :: <br/>$0099 $1FF0 BTFSS STACK_0, 7<br/>;math.ppas,63 :: <br/>$009A $28A1 GOTO $+7<br/>;math.ppas,64 :: <br/>$009B $0874 MOVF STACK_4, W<br/>;math.ppas,65 :: <br/>$009C $07FA ADDWF STACK_10, F<br/>;math.ppas,66 :: <br/>$009D $0875 MOVF STACK_5, W<br/>;math.ppas,67 :: <br/>$009E $1803 BTFSC STATUS, C<br/>;math.ppas,68 :: <br/>$009F $0F75 INCFSZ STACK_5, W<br/>;math.ppas,69 :: <br/>$00A0 $07FB ADDWF STACK_11, F<br/>;math.ppas,70 :: <br/>$00A1 $0CFB RRF STACK_11, F<br/>;math.ppas,71 :: <br/>$00A2 $0CFA RRF STACK_10, F<br/>;math.ppas,72 :: <br/>$00A3 $0CF9 RRF STACK_9, F<br/>;math.ppas,73 :: <br/>$00A4 $0CF8 RRF STACK_8, F<br/>;math.ppas,74 :: <br/>$00A5 $1C03 BTFSS STATUS, C<br/>;math.ppas,75 :: <br/>$00A6 $288C GOTO $-26<br/>;math.ppas,76 :: <br/>$00A7 $087B MOVF STACK_11, W<br/>;math.ppas,77 :: <br/>$00A8 $00F3 MOVWF STACK_3<br/>;math.ppas,78 :: <br/>$00A9 $087A MOVF STACK_10, W<br/>;math.ppas,79 :: <br/>$00AA $00F2 MOVWF STACK_2<br/>;math.ppas,80 :: <br/>$00AB $0879 MOVF STACK_9, W<br/>;math.ppas,81 :: <br/>$00AC $00F1 MOVWF STACK_1<br/>;math.ppas,82 :: <br/>$00AD $0878 MOVF STACK_8, W<br/>;math.ppas,83 :: <br/>$00AE $00F0 MOVWF STACK_0<br/>;math.ppas,84 :: <br/>$00AF $ math_L_1:<br/>;math.ppas,85 :: <br/>$00AF $0008 RETURN<br/>$00DD $ _pwm_start:<br/>;PWM_c5.ppas,26 :: <br/>;PWM_c5.ppas,27 :: <br/>$00DD $1303 BCF STATUS, RP1<br/>$00DE $1683 BSF STATUS, RP0<br/>$00DF $1287 BCF TRISC, 5<br/>;PWM_c5.ppas,28 :: <br/>$00E0 $1283 BCF STATUS, RP0<br/>$00E1 $1512 BSF T2CON, 2<br/>;PWM_c5.ppas,29 :: <br/>$00E2 $300C MOVLW 12<br/>$00E3 $0495 IORWF CCP1CON, 1<br/>$00E4 $ PWM_c5_L_2:<br/>;PWM_c5.ppas,30 :: <br/>$00E4 $0008 RETURN<br/>$004C $ _adc_read:<br/>;ADClib_A_B.ppas,12 :: <br/>;ADClib_A_B.ppas,13 :: <br/>$004C $3040 MOVLW 64<br/>$004D $1303 BCF STATUS, RP1<br/>$004E $1283 BCF STATUS, RP0<br/>$004F $059F ANDWF ADCON0, 1<br/>;ADClib_A_B.ppas,14 :: <br/>$0050 $30F0 MOVLW 240<br/>$0051 $1683 BSF STATUS, RP0<br/>$0052 $049F IORWF ADCON1, 1<br/>;ADClib_A_B.ppas,15 :: <br/>$0053 $1283 BCF STATUS, RP0<br/>$0054 $179F BSF ADCON0, 7<br/>;ADClib_A_B.ppas,16 :: <br/>$0055 $0822 MOVF FARG_ADC_read, 0<br/>$0056 $00F0 MOVWF STACK_0<br/>$0057 $0DF0 RLF STACK_0, 1<br/>$0058 $1070 BCF STACK_0, 0<br/>$0059 $0DF0 RLF STACK_0, 1<br/>$005A $1070 BCF STACK_0, 0<br/>$005B $0870 MOVF STACK_0, 0<br/>$005C $049F IORWF ADCON0, 1<br/>;ADClib_A_B.ppas,17 :: <br/>$005D $141F BSF ADCON0, 0<br/>;ADClib_A_B.ppas,18 :: <br/>$005E $20D5 CALL _delay_22us<br/>;ADClib_A_B.ppas,19 :: <br/>$005F $149F BSF ADCON0, 1<br/>;ADClib_A_B.ppas,20 :: <br/>$0060 $ ADClib_A_B_L_2:<br/>$0060 $081F MOVF ADCON0, 0<br/>$0061 $00F2 MOVWF STACK_2<br/>$0062 $3000 MOVLW 0<br/>$0063 $18F2 BTFSC STACK_2, 1<br/>$0064 $3001 MOVLW 1<br/>$0065 $00F2 MOVWF STACK_2<br/>$0066 $0872 MOVF STACK_2, 0<br/>$0067 $3A01 XORLW 1<br/>$0068 $1D03 BTFSS STATUS, Z<br/>$0069 $286C GOTO ADClib_A_B_L_3<br/>;ADClib_A_B.ppas,21 :: <br/>$006A $0000 NOP<br/>$006B $2860 GOTO ADClib_A_B_L_2<br/>$006C $ ADClib_A_B_L_3:<br/>;ADClib_A_B.ppas,22 :: <br/>$006C $081E MOVF ADRESH, 0<br/>$006D $00F2 MOVWF STACK_2<br/>$006E $01F3 CLRF STACK_2+1<br/>$006F $0872 MOVF STACK_2, 0<br/>$0070 $00F3 MOVWF STACK_2+1<br/>$0071 $01F2 CLRF STACK_2<br/>$0072 $0872 MOVF STACK_2, 0<br/>$0073 $00A3 MOVWF _adc_read_local_result<br/>$0074 $0873 MOVF STACK_2+1, 0<br/>$0075 $00A4 MOVWF _adc_read_local_result+1<br/>;ADClib_A_B.ppas,23 :: <br/>$0076 $1683 BSF STATUS, RP0<br/>$0077 $081E MOVF ADRESL, 0<br/>$0078 $0472 IORWF STACK_2, 0<br/>$0079 $1283 BCF STATUS, RP0<br/>$007A $00A3 MOVWF _adc_read_local_result<br/>$007B $0873 MOVF STACK_2+1, 0<br/>$007C $00A4 MOVWF _adc_read_local_result+1<br/>$007D $3000 MOVLW 0<br/>$007E $04A4 IORWF _adc_read_local_result+1, 1<br/>;ADClib_A_B.ppas,24 :: <br/>$007F $101F BCF ADCON0, 0<br/>$0080 $ ADClib_A_B_L_0:<br/>;ADClib_A_B.ppas,25 :: <br/>$0080 $0823 MOVF _adc_read_local_result, 0<br/>$0081 $00F0 MOVWF STACK_0<br/>$0082 $0824 MOVF _adc_read_local_result+1, 0<br/>$0083 $00F1 MOVWF STACK_0+1<br/>$0084 $0008 RETURN<br/>$0004 $ _pwm_change_duty:<br/>;PWM_c5.ppas,17 :: <br/>;PWM_c5.ppas,18 :: <br/>$0004 $1303 BCF STATUS, RP1<br/>$0005 $1683 BSF STATUS, RP0<br/>$0006 $0812 MOVF PR2, 0<br/>$0007 $00F0 MOVWF STACK_0<br/>$0008 $01F1 CLRF STACK_0+1<br/>$0009 $0870 MOVF STACK_0, 0<br/>$000A $3F01 ADDLW 1<br/>$000B $00F4 MOVWF STACK_4<br/>$000C $3000 MOVLW 0<br/>$000D $1803 BTFSC STATUS, C<br/>$000E $3F01 ADDLW 1<br/>$000F $0771 ADDWF STACK_0+1, 0<br/>$0010 $00F5 MOVWF STACK_4+1<br/>$0011 $1283 BCF STATUS, RP0<br/>$0012 $0822 MOVF FARG_PWM_Change_Duty, 0<br/>$0013 $00F0 MOVWF STACK_0<br/>$0014 $01F1 CLRF STACK_0+1<br/>$0015 $2085 CALL _mul_16x16_u<br/>$0016 $3006 MOVLW 6<br/>$0017 $00F2 MOVWF STACK_2<br/>$0018 $0870 MOVF STACK_0, 0<br/>$0019 $00F8 MOVWF STACK_8<br/>$001A $0871 MOVF STACK_0+1, 0<br/>$001B $00F9 MOVWF STACK_8+1<br/>$001C $0872 MOVF STACK_2, 0<br/>$001D $ L_PWM_Change_Duty_0:<br/>$001D $1903 BTFSC STATUS, Z<br/>$001E $2824 GOTO L_PWM_Change_Duty_1<br/>$001F $0CF9 RRF STACK_8+1, 1<br/>$0020 $0CF8 RRF STACK_8, 1<br/>$0021 $13F9 BCF STACK_8+1, 7<br/>$0022 $3FFF ADDLW 255<br/>$0023 $281D GOTO L_PWM_Change_Duty_0<br/>$0024 $ L_PWM_Change_Duty_1:<br/>;PWM_c5.ppas,19 :: <br/>$0024 $0878 MOVF STACK_8, 0<br/>$0025 $00F0 MOVWF STACK_0<br/>$0026 $0879 MOVF STACK_8+1, 0<br/>$0027 $00F1 MOVWF STACK_0+1<br/>$0028 $0DF0 RLF STACK_0, 1<br/>$0029 $0DF1 RLF STACK_0+1, 1<br/>$002A $1070 BCF STACK_0, 0<br/>$002B $0DF0 RLF STACK_0, 1<br/>$002C $0DF1 RLF STACK_0+1, 1<br/>$002D $1070 BCF STACK_0, 0<br/>$002E $0DF0 RLF STACK_0, 1<br/>$002F $0DF1 RLF STACK_0+1, 1<br/>$0030 $1070 BCF STACK_0, 0<br/>$0031 $0DF0 RLF STACK_0, 1<br/>$0032 $0DF1 RLF STACK_0+1, 1<br/>$0033 $1070 BCF STACK_0, 0<br/>$0034 $3030 MOVLW 48<br/>$0035 $0570 ANDWF STACK_0, 0<br/>$0036 $00F6 MOVWF STACK_6<br/>$0037 $0871 MOVF STACK_0+1, 0<br/>$0038 $00F7 MOVWF STACK_6+1<br/>$0039 $3000 MOVLW 0<br/>$003A $05F7 ANDWF STACK_6+1, 1<br/>;PWM_c5.ppas,20 :: <br/>$003B $0878 MOVF STACK_8, 0<br/>$003C $00F0 MOVWF STACK_0<br/>$003D $0879 MOVF STACK_8+1, 0<br/>$003E $00F1 MOVWF STACK_0+1<br/>$003F $0CF1 RRF STACK_0+1, 1<br/>$0040 $0CF0 RRF STACK_0, 1<br/>$0041 $13F1 BCF STACK_0+1, 7<br/>$0042 $0CF1 RRF STACK_0+1, 1<br/>$0043 $0CF0 RRF STACK_0, 1<br/>$0044 $13F1 BCF STACK_0+1, 7<br/>$0045 $0870 MOVF STACK_0, 0<br/>$0046 $0093 MOVWF CCPR1L<br/>;PWM_c5.ppas,21 :: <br/>$0047 $300F MOVLW 15<br/>$0048 $0595 ANDWF CCP1CON, 1<br/>;PWM_c5.ppas,22 :: <br/>$0049 $0876 MOVF STACK_6, 0<br/>$004A $0495 IORWF CCP1CON, 1<br/>$004B $ PWM_c5_L_1:<br/>;PWM_c5.ppas,23 :: <br/>$004B $0008 RETURN<br/>$00E5 $ _pwm_init:<br/>;PWM_c5.ppas,8 :: <br/>;PWM_c5.ppas,9 :: <br/>$00E5 $1303 BCF STATUS, RP1<br/>$00E6 $1283 BCF STATUS, RP0<br/>$00E7 $0193 CLRF CCPR1L, 1<br/>;PWM_c5.ppas,10 :: <br/>$00E8 $1215 BCF CCP1CON, 4<br/>;PWM_c5.ppas,11 :: <br/>$00E9 $1295 BCF CCP1CON, 5<br/>$00EA $ PWM_c5_L_0:<br/>;PWM_c5.ppas,12 :: <br/>$00EA $0008 RETURN<br/>$00B0 $ _main:<br/>;ledlightcontrol for clock.pbas,6 :: main:<br/>$00B0 $ _main_main:<br/>;ledlightcontrol for clock.pbas,9 :: porta =%00000001 rem porta 0 is adc input<br/>$00B0 $3001 MOVLW 1<br/>$00B1 $1303 BCF STATUS, RP1<br/>$00B2 $1283 BCF STATUS, RP0<br/>$00B3 $0085 MOVWF PORTA<br/>;ledlightcontrol for clock.pbas,10 :: cmcon0=%00000111 rem disable comparitors<br/>$00B4 $3007 MOVLW 7<br/>$00B5 $0099 MOVWF CMCON0<br/>;ledlightcontrol for clock.pbas,11 :: PORTC = $00 ' Initialize PORTC digital outputs<br/>$00B6 $0187 CLRF PORTC, 1<br/>;ledlightcontrol for clock.pbas,12 :: Pwm_Init(5000) ' Initialize PWM module, freq = 1.5kHz.<br/>$00B7 $1012 BCF T2CON, T2CKPS0<br/>$00B8 $1092 BCF T2CON, T2CKPS1<br/>$00B9 $1412 BSF T2CON, T2CKPS0<br/>$00BA $30F9 MOVLW 249<br/>$00BB $1683 BSF STATUS, RP0<br/>$00BC $0092 MOVWF PR2<br/>$00BD $20E5 CALL _pwm_init<br/>;ledlightcontrol for clock.pbas,13 :: Pwm_Start ' Start PWM<br/>$00BE $20DD CALL _pwm_start<br/>;ledlightcontrol for clock.pbas,15 :: while true<br/>$00BF $ ledlightcontrol for clock_L_2:<br/>;ledlightcontrol for clock.pbas,16 :: j = adc_read(0)<br/>$00BF $01A2 CLRF FARG_ADC_read, 1<br/>$00C0 $204C CALL _adc_read<br/>$00C1 $0870 MOVF STACK_0, 0<br/>$00C2 $00A0 MOVWF _j<br/>$00C3 $0871 MOVF STACK_0+1, 0<br/>$00C4 $00A1 MOVWF _j+1<br/>;ledlightcontrol for clock.pbas,17 :: if j>255 then j=255<br/>$00C5 $0871 MOVF STACK_0+1, 0<br/>$00C6 $3C00 SUBLW 0<br/>$00C7 $1D03 BTFSS STATUS, Z<br/>$00C8 $28CB GOTO L_main_0<br/>$00C9 $0870 MOVF STACK_0, 0<br/>$00CA $3CFF SUBLW 255<br/>$00CB $ L_main_0:<br/>$00CB $1803 BTFSC STATUS, C<br/>$00CC $28D0 GOTO ledlightcontrol for clock_L_7<br/>$00CD $ ledlightcontrol for clock_L_6:<br/>$00CD $30FF MOVLW 255<br/>$00CE $00A0 MOVWF _j<br/>$00CF $01A1 CLRF _j+1<br/>$00D0 $ ledlightcontrol for clock_L_7:<br/>;ledlightcontrol for clock.pbas,18 :: end if<br/>$00D0 $ ledlightcontrol for clock_L_8:<br/>;ledlightcontrol for clock.pbas,22 :: Pwm_Change_Duty(j) ' Change duty ratio<br/>$00D0 $0820 MOVF _j, 0<br/>$00D1 $00A2 MOVWF FARG_PWM_Change_Duty<br/>$00D2 $2004 CALL _pwm_change_duty<br/>$00D3 $28BF GOTO ledlightcontrol for clock_L_2<br/>;ledlightcontrol for clock.pbas,24 :: wend<br/>$00D4 $28D4 GOTO $<br/><br/>

Thank you very much for the assembly version. Appreciate it.

Its much shorter in basic. If you want a copy of the basic script I can let you have that as well:

its much shorter in Basic, if you want a copy of the basic script I can post that for you.

url link doesn't work

Just a quick question
when you first power it on shouldnt the LEDS be off? and only turn on when you shield it?
the first paragraph made it sound the other way around
Great project though I like it

no sorry, that's the opposite of the desired effect. The idea is that the illumination is just enough to see the clock in the dark and as the light increases, so does the illumination. In other words the light shining on the clock is always a little brighter than the ambient light.
I know that sounds crazy, because normally one does the opposite!

No i agree. I wasnt sure which you were using in the first step you said it was inversely proportional to the ambient light . I think having light proportonal to the ambient light is a better idea. How ever can you incorporate limits into it? so that unless turned off in complete darkness there will still be some illumination , and if the ambient light becomes great enough (ie a sunlit bedroom) the LEDs fade to off as well as they wont be needed.
sort of maximum and minimums

OK, Good point about my inverse proportionality Hi Hi, I should have considered my wording a little more. Your idea of limiting both ends of the lighting range is fine. The lower end (Darkness) is in fact limited, however in my application I saw now reason to limit the top end as in very bright light one can ignore the clock lighting, and also the small power consumed by the unit is hardly a problem. Perhaps if someone has a reason for a battery powered unit I would incorporate the high (Bright light) lighting turn off function.Thanks for your comments, Brian

No i agree. I wasnt sure which you were using in the first step you said it was inversely proportional to the ambient light . I think having light proportonal to the ambient light is a better idea. How ever can you incorporate limits into it? so that unless turned off in complete darkness there will still be some illumination , and if the ambient light becomes great enough (ie a sunlit bedroom) the LEDs fade to off as well as they wont be needed.
sort of maximum and minimums

Such complexity! One pines for the not-so-good old days when the problem would be solved with a dash of radium paint on the dial. "Oh! those pesky labour standards laws. How they strive to thwart the mighty engine of Market Capitalism."

Radium is a good Idea again, but I think we have enough cancer in our radioactive world!

Why not put a switch, a capacitor, an LED and a resistor together like this;
resistor connected to LED, LED + resistor connected in parallel to the capacitor
capacitor connected to switch, switch connected to power supply, (series connection)
Your project is a little bit too complex just for the purpose of illuminating your clock

Thank you for your comment, Sorry you have missed the point! Your suggestions is too simple to meet the requirements of accurate tracking of the light changes. The function is to keep the light at a minimum level that can still allow one to read the clock face in all ranges of low light ambient.
You can only slightly alter the brightness range of an LED by a variable voltage (Ie. your suggestion of a capacitor and resistor), if one wishes to have a full range of light to dark or the reverse, one must fool the eye by switching the lED on and off at a variable length of on/off ie. PWM, (pulse width modulation). Naturally, one can achieve this by other methods, but the way it is done with the above circuit is low cost and simple. There is a period in the early hours of the morning and late in the evening where the ambient light changes very gradually, and the above circuitry compensates very accurately for this

oh....
i see
For that purpose, it is pretty simple, i though you just wanted the clock illuminated, in no special way