Instructions

The program
03ampel
controls the traffic light
4. Day
RGB-LEDs
A normal LED is always lit in only one colour. The colour of the LEDs in the Advent calendar are evident even with the LED off. There also are
LEDs that appear transparent and that will only show their colour when current is flowing. RGB-LEDs can be lit in different colours. Generally,
three LEDs with different colours are installed in a transparent housing here. Each of these three LEDs has its own anode, through which it is
connected to a GPIO pin. The cathode, which is connected to the ground line, is only present once. Therefore, an RGB-LED has four connection
wires.
The connection wires of RGB-LEDs have different lengths to identify them clearly. In contrast to regular LEDs, the cathode is the longest wire
here.
RGB-LEDs work like three individual LEDs and therefore also need three dropping resistors.
RGB-LED flashes in different colours
The experiment of the 4th day makes an RGB-LED flash randomly in different colours.
Components: 1 x plug board, 1 x RGB LED, 3 x 220-Ohm resistor, 4 x connection cables
The program
The RGB-LED is connected to three GPIO-Pins with subsequent numbers. This permits control via a random number between 11 and 13. At every
loop passage, one of the three pins of the RGB-LED is switched on at random. For this, the program generates a random number in the range
11...13. Two nested connect-blocks generate one of these texts from this: pin11on, pin12on, pin13on. In Scratch, numbers and character chains
can be linked into character chains as desired, while other programming languages often only permit this after prior conversion. Then a similar
block will randomly switch off one of the three pins of the RGB-LED. Since in both cases the switching condition of the respective pin will not be
checked first, any imaginable combination of colours switched on and off may result after a few loop passages.
How are random numbers generated?
Generally, it is assumed that nothing can happen at
random in a program. – So how can a program be able
to generate random numbers? Dividing a large prime
number by any value, this will lead to figures that are