Advertisement  

Saturday, 28 March 2020
     
 
Main Menu
Home Home
Shop Shop
News News
BASCOM-AVR BASCOM-AVR
BASCOM-8051 BASCOM-8051
Products Products
Application Notes Application Notes
Publications Publications
Links Links
Support Center Support Center
Downloads Downloads
Forum Forum
Resellers Resellers
Contact Us Contact Us
Updates Updates
MCS Wiki MCS Wiki
Online Help
BASCOM-AVR Help BASCOM-AVR Help
BASCOM-8051 Help BASCOM-8051 Help
Contents in Cart
Show Cart
Your Cart is currently empty.
Search the Shop

Products Search

User Login
Username

Password

If you have problem after log in with disappeared login data, please press F5 in your browser

RSS News
 
     
 

 
   
     
 
AN #188 - Fiber-optic Christmas tree Print
Fiber-optic Christmas tree

The Xmas tree  controller won the third price in the Ukraine BASCOM 2010 completion! 

The following text is translated by Vasiliy, thanks!

I wanted to joy myself and my friends on New Year’s and I bought a synthetic Christmas tree with an FO illumination IGT040EG1. The tree was 40 cm high and was powered by 3 AA batteries with total voltage 4,5 V. I switched the tree on in a dark room and prepared to see a nice light show, but I was surprised when the tree began to flash red and yellow in turn.

This synthetic wonder was operated by a small board with a bun-like chip, which switched two bright LEDs of red and yellow color in turn. Among the tree branches there was a separate hanging garland made of LEDs of white color, which shined brightly by switching on the tree. At the top of the tree was a transparent plastic star with some LEDs inside. The star was electrically connected with the garland and was switched on with it at the same time. This is strictly speaking all that I can say about this original product of Chinese industry.


I supposed that technical possibilities of the tree allow to reproduce more lighting effects and I have worked out a control board on micro controller Atmega 8L-8, which is mounted instead of the old one. In this new variant the tree creates very beautiful light patterns and dynamic effects, it can work in 4 modes: automatic, acoustic clap switch, acoustic-interactive, photo detector.

Here are some of the realized lighting effects: fast switchings of three-colored LEDs (for each color), lighting effect «shimmer» (for each color), color mixing, fast switching on – fluent switching off, consecutive switching of LEDs crystals with an effect of light accumulation and changing, color impulses with a small pause (for each color), increase of flash frequency, alternate switching from tree to garland with glow color changing, etc. The use of bright RGB-LEDs allows to watch lighting effects by the daylight, but the best results turn out in a dark room or by the switched off overhead illumination.

The garland situated on the tree shined too bright, so I had to limit programmatic the glow brightness level. For energy economy and for luminous emittance leveling of the garland and the tree the garland operating occurs with the impulse duration less than 50% from the initial. Besides, the garland is switched on not in all program units but only in the last three. The garland reproduces the following lighting effects: flashes, fast switching on – fluent switching off, switchings, shimmering.

Switching from one mode to another is realized cyclic by the short pressure of the button on the upper frame cover. The two-colored LED (red-blue) placed near fulfills service options indicating active working mode.  An external interrupt at the microcontroller INT0  output is used for button SB1 operating. That’s why button mode switching can be made at any moment.

In the automatic mode the indicating LED is not shining, there is no need to push the mode choice button. The automatic mode starts just after the power is switched on (at the frame bottom) and then reproduces cyclic programmed lighting effects. The mode changing is possible by single short pressures of the button SB1. Control board reproduces cyclic 12 complicated program units, which create an original light pattern on the tree. Every lighting effect is reproduced for each color, so the total amount is 36 effects. A single effect for every color is repeated many times, it also increases the total amount of reproduced effects. The automatic mode is convenient because it doesn’t require efficient intervention; the program makes everything creating different light patterns on the tree surface.

In the acoustic mode «сlap switch» the indicating LED HL1 shines continuously with red color. The mode is switched on by one short pressure of the button SB1. The tree switches on only after the third clap and it will continue to work autonomously reproducing lighting effects. At the clap moment the indicating LED is going out for a split second, it confirms the received sound signal. After the third clap all following claps won’t be effective. For restart the button SB1 should be pushed 3 times. This mode can be used at parties and holidays for attracting attention and creating a mysterious atmosphere.

Switching on the second acoustic mode «interactive»: the button SB1 should be pushed 2 times (if at the beginning) or once if the previous mode is changing. The indicating LED will shine blue, and then it’s possible to start interactive three-colored composite effect. The tree will respond to every sound signal with fast successive reproducing of three colors: blue, red and green. The sensitiveness to sound signals in this mode is very high and the device will react even to human speech. The color symphony can play a role of an accompaniment to karaoke songs or to music.

Switching on the mode «photodetector»: the button SB1 should be pushed 3 times (if at the beginning) or once if previous mode is changing. When the mode is switched on the indicating LED HL1 will flash red. It means that the beginning of a programmed test of the room illumination level. That’s why it’s recommended to switch on this mode by the already turned on general illumination of the room. The slightest darkening or turning the light off will lead to reproducing programmed lighting effects. The specific of the mode «photodetector» is that just the light in the room is turned on once again the lighting effect on the tree switches off. The following turning-off the light in the room lights the illumination on the tree again etc… The reason is that the phototransistor is connected to the second microcontroller external interrupt INT1, which allows to start or to stop efficiently the lighting effects program.

The next pressure of the button SB1 switches the program into the first mode. In order to prevent the bounce the stop in the interrupts are a bit more than usual. It shows by sight as a rather late mode switching.

The electric scheme is based on the microcontroller Atmega8L-8 with a minimal supply voltage level ca. 2,7V. The choice of this microcontroller is caused by the limit of supply voltage in form of a tree batteries set with common voltage 4,5V. To prolong the batteries operating life and to raise efficiency all component parts are powered by a pulse-duration conversion device MC34063AP. Out voltage 3,5V after resistors R6R8 comes to the microcontroller, indicating LED HL1, three-colored LEDs HL2-HL5, note amplifier, and transistor VT1.

For sound signals reception and analysis I’ve built a low-frequency amplifier on transistor VT1. Sound signal appears on the microphone port BM1 as weak electric impulses. They come through the capacitor C3 and the transistor amplifier’s base where they have voltage amplification. Then the intensified sound signal comes from the upper (due the scheme) resistor terminal R5 to the microcontroller’s port 28 ADC5 and is digitalized. Then the volume level and the pause between signals are programmatic analyzed. For the second mode «clap switching » the acoustic signal becomes considerably weaker and the pause control between signals is used.  On the contrary, for the mode «acoustic – interactive» the signal amplification is programmatic realized and the tree can react to common human speech. The device sensibility to sound signal can be changed not only programmatic but also by changing the resistance of the resistor R5.

The following is programmed in the microcontroller DD1 cell:  the routines of lighting effects reproducing and the signals of out sensors of photo transistor VT2, button SB1 and amplifier output. The inner generator RC 4 MHz is hooked up programmatically. The program is written on BASIC in BASCOM-AVR software-envelope and is a bit more than 4Kb. To set fuse bits by programming is not needed. Resistor R16 disables an inadvertent trip-out by voltage reduction in the feed network.

Crystal operating of each HL2-HL5 LEDs is organized due the program.  In order to create a great variety of effects all cathodes are hooked up through the FET VT1, which functions in pulse-time modulation mode. This signal comes from the OC1A port and allows turning all three-colored LEDs on and off fluent. The garland on the tree is operated by the same way. It’s operated by the global bus which is hooked up through the FET VT4. The operating signal comes from the microcontroller to FET VT4.  The impulse duration in the signal is changed due the given program. It shows in different lighting effects on the garland. The microcontroller not only operates RGB-LEDs but also combines their switching on with the LED-garland. As a result there are composite lighting effects.


Parts and materials

The printed-circuit board (dr.2) is made from a single-sided glass-fiber laminate sheet with thickness 1,5-2 mm. The dimensions are 60,2x60,2 mm. Radio elements are mounted due the dr. 3. The list of radio elements you can see in the table1. The shape of the printed-circuit board has a figured notch where plastic pin for a screw should be placed after the installation of the board in the frame.


Please pay attention to phototransistor VT2, two-colored LED HL1 and button SB1 setting. They are mounted after all radio parts. You need to prepare 2 holes for phototransistor and LED on the upper frame cover beforehand. By the mounting of phototransistor and LED the length of legs should be so that the upper cover can close free and the frames of the details slightly outlook from the holes.

After marking-off  you need to make two holes on the upper cover for the button setting (see the photo). The diameter of the holes is ca. 1 mm. The button pins are passed through the holes and are incurved from the opposite side. The button is connected with the board with 2 bounding wires. There’s no need to make special holes for the microphone, the high sensibility of the scheme allows receiving sound signals in close frame.

Here can be used any 3 mm two-colored LED of red and blue colors.

List of radio parts

Position

Name

Comment

Quantity, pcs

DD1

Altmega8L-8

Replacement is not recommended!

1

DA1

MC34063AP

 

1

VT1

BC547

 

1

VT2

ФТ-2К

phototransistor

1

VT3,VT4

КП505А

BS170P

2

R1

5,1 kO

0,125W

1

R2

470kO

0,125W

1

R3

22kO

0,125W

1

R4

1 kO

0,125W

1

R5

120 kO

0,125W

1

R6

1,2 kO

0,125W

1

R7

1,5 mO

0,125W

1

R8

2,2 kO

0,125W

1

R9-R11,R13-R15,R17-R22

220 О

0,125W

12

R12

470 О

0,125W

1

R16

2 kO

0,125W

1

BM1

DN9767

Electret small microphone

1

C1,C6

220uF10V

 

2

C2

22uF6,3V

 

1

C3,C5,C7,C8

0,1uF

 

4

C4

470picofarad

 

1

L1

240uH

 

1

VD1

1N5819

 

1

HL1

L57EGW or analogue

 

1

HL2-HL5

L5013RGB

 

4

SB1

Two-pin- button

 

1

XT1

Two-sectional - joint

 

1

-

Panel for microcontroller

DIP28pin

1

 


Source code


'------------------------------------------------------------------------------
'name                    : UPGREYD ELKA.bas
'copyright              : (c) 2008, author Lechkin AV
'purpose                : demonstration of lighting effects (15 effects)
'micro                   : ATMega8-8
'crystal                  : 4 MHz internal oscillator
'------------------------------------------------------------------------------

 $regfile = "m8def.dat" 'connect the description of the microcontroller
 $crystal = 4000000                                       'establish the frequency of internal oscillator 4Mhz

 Config Portb = Output
 Config Pind.= Input
 Config Pind.= Input
 Config Portd.= Output
 Config Portd.= Output
 Config Portd.= Output
 Config Portd.= Output
 Config Portd.= Output
 Config Pinc.= Input
 Config Portc.= Output
 Config Portc.= Output
 Config Portc.= Output
 Config Portc.= Output
 Config Portc.= Output

 Dim R1 As Byte 'declare variables
 Dim R2 As Byte
 Dim R3 As Byte
 Dim X As Byte
 Dim X2 As Byte
 Dim Flag1 As Byte
 Dim W1 As Word

 Config Adc = Single , Prescaler = 8 , Reference = Internal 'configures the ADC
 Stop Adc 'Stop the ADC

 'configures the timer PWM on pines and PB.1 PB.2
 Config Timer1 = Pwm , Pwm = 8 , Prescale = 1 , Compare A Pwm = Clear Down , Compare B Pwm = Clear Down

 Config Int0 = Falling                                    'allow interruption of the voltage drop
 On Int0 Button                                           'transition to interrupt to the label Button
 Config Int1 = Low Level                                  'allow interrupts at a low level
 On Int1 Foto2                                            'transition to interrupt to the label Foto2
 Enable Interrupts 'allow all interrupts
 Enable Int0 'include an interruption in the Pin INT0
 Disable Int1 'disable interruptions on Pin INT1

 Pwm1a = 255                                              'setting a maximum pulse duration OC1A


'-------------------------------------------------------------------------------
'                      Status indicator LEDs HL2
'-------------------------------------------------------------------------------

'There is no glow-play lighting effects on the program
'Red-play integration of lighting effects on the three cotton
'Blue-interactive switch LEDs on a sound signal
'Flashing red mode photodetector (phototransistor included in shading)

'-------------------------------------------------------------------------------




Do 'beginning of the main program

'-------------------------------------------------------------------------------
'                               LIGHTING EFFECTS
'-------------------------------------------------------------------------------



'1-----------fast switching tri-color LEDs-----------------------

Ef1:

 For R1 = 1 To 15                                         'beginning of the cycle
 Pulseout Portd , 5 , 25000                               'generation of the output pulse portd.5
 Pulseout Portb , 0 , 25000
 Pulseout Portb , 5 , 25000
 Pulseout Portc , 2 , 25000
 If Flag1 = 1 And X2 = 1 Then Goto Audio1              'transition condition on the label Audio1
 If Flag1 = 2 Then Goto Interactiv                     'transition condition on the label Interactiv
 Pulseout Portd , 6 , 25000
 Pulseout Portb , 3 , 25000
 Pulseout Portc , 0 , 25000
 Pulseout Portc , 3 , 25000
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Pulseout Portd , 7 , 25000
 Pulseout Portb , 4 , 25000
 Pulseout Portc , 1 , 25000
 Pulseout Portc , 4 , 25000
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Next 'end loop
   X = 0

 '2-------------gradual extinction of LEDs------------------------------------

Ef2:

 Incr X                                                   'increase in the variable X by one
 Gosub Fricolor                                           'go to subroutine Fricolor

   R2 = 255
 For R1 = 1 To 255
 Decr R2
 Pwm1a = R2
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Waitms 3
 Next
 If X < 3 Then Goto Ef2
 Portd.= 0
 Portb.= 0
 Portc.= 0
 Portc.= 0
 Pwm1a = 255


 '3-----sequential switching crystal LEDs------------------

Ef3:

 For R1 = 1 To 5
 Portd.= 0
 Portd.= 1
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Waitms 50
 Portb.= 0
 Portb.= 1
 Waitms 50
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Portb.= 0
 Portc.= 1
 Waitms 50
 Portc.= 0
 Portc.= 1
 Waitms 50
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Portd.= 0
 Portd.= 1
 Waitms 50
 Portb.= 0
 Portb.= 1
 Waitms 50
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Portc.= 0
 Portc.= 1
 Waitms 50
 Portc.= 0
 Portc.= 1
 Waitms 50
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Portd.= 0
 Portd.= 1
 Waitms 50
 Portb.= 0
 Portb.= 1
 Waitms 50
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Portc.= 0
 Portb.= 1
 Waitms 50
 Portc.= 0
 Portc.= 1
 Waitms 50
 Next


 '4---light effect "flicker" with a consistent change in emission color-----

Ef4:

   R3 = 10
 For R1 = 1 To 70
 Gosub Bcolor
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Waitms 10
 Next

 For R1 = 1 To 70
 Gosub Rcolor
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Waitms 10
 Next

 For R1 = 1 To 70
 Gosub Gcolor
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Waitms 10
 Next


 '5---------------mixing of three colors----------------------------------

Ef5:

 For R1 = 1 To 10
 Portd.= 1 : Portb.= 1
 Portc.= 1 : Portc.= 1

 Portb.= 0 : Portc.= 0
 Portd.= 0 : Portb.= 0
 Waitms 70
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Portd.= 0 : Portb.= 0
 Portd.= 1 : Portb.= 1
 Portc.= 1 : Portc.= 1
 Waitms 70
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Portc.= 0 : Portc.= 0
 Portb.= 1 : Portc.= 1
 Portd.= 1 : Portb.= 1
 Waitms 70
 Next
 Portd.= 0 : Portb.= 0


 '6-------------short-term suppression of each color-------------------------

Ef6:

   R3 = 60

 For R1 = 1 To 10
 Gosub Bcolor
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Waitms 7
 Next

 For R1 = 0 To 10
 Gosub Rcolor
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Waitms 7
 Next

 For R1 = 0 To 10
 Gosub Gcolor
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Waitms 7
 Next


 '7--------------increasing the frequency of outbreaks-----------------------------------

Ef7:

 For R1 = 1 To 3
   R3 = 60

 For R2 = 1 To 60
 Decr R3
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 If R1 = 1 Then
 Gosub Rcolor
 End If
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 If R1 = 2 Then
 Gosub Gcolor
 End If
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 If R1 = 3 Then
 Gosub Bcolor
 End If
 Waitms 10
 Next
 Next


 '8---------sequential switching of LEDs-------------------------

Ef8:

   R3 = 50
 For R1 = 1 To 10
 Gosub Bcolor
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Gosub Rcolor
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Gosub Gcolor
 Next



 '9--------flickering lights on a blue, red and green background-------------------

Ef9:

   X = 1
 For R1 = 1 To 3
 Gosub Fricolor
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Incr X

 For R2 = 1 To 100
 Pwm1b = 70
 Waitms 5
 Pwm1b = 0
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Waitms 5
 Next
 Next
 Portd.= 0 : Portb.= 0 : Portc.= 0 : Portc.= 0


 '10----------rapid ignition and smooth clearing garland--------------------

Ef10:

   X = 1
 For R1 = 1 To 3
 Gosub Fricolor
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Incr X

   R3 = 100
 Pwm1b = R3

 For R2 = 1 To 100
 Decr R3
 Pwm1b = R3
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Waitms 7
 Next
 Next
 Portd.= 0 : Portb.= 0 : Portc.= 0 : Portc.= 0


 '11----toggle garland, Christmas tree with different colors-----------

Ef11:

   R3 = 100
 For R1 = 1 To 10
 Gosub Bcolor
 Pwm1b = 70
 Waitms 10
 Pwm1b = 0
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Gosub Rcolor
 Pwm1b = 70
 Waitms 10
 Pwm1b = 0
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Gosub Gcolor
 Pwm1b = 70
 Waitms 10
 Pwm1b = 0
 Next

 '12----flash lights on the background of purple glow of Christmas tree------------

Ef12:

 For R1 = 1 To 10
 For R2 = 1 To 250
 Portd.= 1
 Portb.= 1
 Portb.= 1
 Portc.= 1
 Delay
 Portd.= 0
 Portb.= 0
 Portb.= 0
 Portc.= 0
 If Flag1 = 1 And X2 = 1 Then Goto Audio1
 If Flag1 = 2 Then Goto Interactiv
 Portd.= 1
 Portb.= 1
 Portc.= 1
 Portc.= 1
 Waitus 600
 Portd.= 0
 Portb.= 0
 Portc.= 0
 Portc.= 0
 Next

 Pwm1b = 70
 Waitms 3
 Pwm1b = 0
 Next


Loop



'-------------------------------------------------------------------------------
'     subroutine handler clicks SB1 switch modes
'-------------------------------------------------------------------------------

Button:

 Incr Flag1                                               'increments the variable Flag1 unit

 If Flag1 = 1 Then 'if Flag1 is 1, then turns on the speakers, the inclusion of the cotton
 Start Adc 'include ADC
 Incr X2                                                  'increments the variable X2
 End If 'end conditions
 'if Flag1 is 2, then turns on the speakers interactively
 If Flag1 = 3 Then 'if Flag1 is 3, then turns on the photodetector
 Stop Adc 'stop ADC
 End If

 If Flag1 > 3 Then 'test conditions
 Disable Int1 'disable interrupts on INT1
   Flag1 = 0
   X2 = 0
 End If

 Gifr = 255                                               'write code in the main register interrupt flags
 Waitms 40                                                'delay 40ms
 Return 'return from subroutine


'-------------------------------------------------------------------------------
'              signal handler routine with the phototransistor
'-------------------------------------------------------------------------------

Foto1:

 Portd = &B00000000
 Enable Int1 'the inclusion of an external interrupt int1
 Goto Ef1                                                 'unconditional jump to label Ef1

Foto2:

 Portb = &B00000000                                       'setting bits of data port B
 Portc = &B0000000                                        'setting bits of data port C
 Portd = &B00000001                                       'setting bits of data port D
 Waitms 15                                                'delay 17ěń
 Portd.= 0
 Waitms 15                                                'delay  17ěń
 Return 'return from subroutine

'-------------------------------------------------------------------------------
'              subroutine handler audio for three cotton
'-------------------------------------------------------------------------------

Audio1:

 Portb = &B00000000                                       'setting bits of data port B
 Portc = &B0000000                                        'setting bits of data port C
 Portd = &B00000001                                       'Red led HL2
   W1 = Getadc(5) 'reads data from the ADC, assigning a value to a variable W1
   W1 = W1 * 10                                             'logical operation is equivalent to the input gain
 If Flag1 = 2 Then Goto Interactiv                        'transition condition on the label Interactiv
 If W1 > 440 Then 'expose the threshold of sensitivity to sound
 Incr X2                                                  'increase the variable X2 unit
 Portd.= 0                                              'write logic 0 portd.0 indicator signal reception
 Waitms 30                                                'delay  30ěń
 End If
 If X2 < 4 Then Goto Audio1                               'transition condition on the label Audio1
 Portd.= 0                                              'zero the port D
 Goto Ef1                                                 'unconditional jump to label Ef1

'-------------------------------------------------------------------------------
'       subroutine handler audio mode interactive
'-------------------------------------------------------------------------------

Interactiv:

 Portd = &B00000010                                       'light the blue crystal LEDs HL2
 If Flag1 = 3 Then Goto Foto1                             'if Flag1 equal to 3 then go to the label Foto1
   W1 = Getadc(5) 'reads data from the ADC, assigning a value to a variable W1
   W1 = W1 * 15                                             'logical operation is equivalent to the input gain
 If W1 > 130 Then Goto Color                              'jump on the condition of the labelColor
 Goto Interactiv                                          'unconditional jump to label  Interactiv

Color:
 If Flag1 = 3 Then Goto Foto1                             'if Flag1 equal to 3 then go to the label Foto1
   R3 = 25                                                  'assign to the variable R3 value 25
 Gosub Bcolor                                             'go to subroutine Bcolor
 Gosub Rcolor                                             'go to subroutine Rcolor
 Gosub Gcolor                                             'go to subroutine Gcolor
 Goto Interactiv                                          'unconditional jump to label  Interactiv

'-------------------------------------------------------------------------------
'   routines include crystal LEDs: blue, red, green
'-------------------------------------------------------------------------------

Bcolor: ' blue

 Portd.= 1
 Portb = &B00100001
 Portc.= 1
 Waitms R3
 Portd.= 0
 Portb = &B00000000
 Portc.= 0
 Return

Rcolor: ' red

 Portd.= 1
 Portb.= 1
 Portc = &B0001001
 Waitms R3
 Portd.= 0
 Portb.= 0
 Portc = &B0000000
 Return

Gcolor: ' green

 Portd.= 1
 Portb.= 1
 Portc = &B0010010
 Waitms R3
 Portd = &B00000000
 Portb = &B00000000
 Portc = &B0000000
 Return

Fricolor: ' three colors

 If X = 1 Then
 Portd.= 1
 Portb = &B00100001
 Portc.= 1
 End If
 If X = 2 Then
 Portd.= 0
 Portb = &B00001000
 Portc = &B0001001
 Portd.= 1
 End If
 If X = 3 Then
 Portd.= 0
 Portb = &B00010000
 Portc = &B0010010
 Portd.= 1
 End If
 Return