# 26. case 22 Micro:bit Helix#

## 26.1. Introduction#

In this article, let’s learn how to draw a helix with micro:bit. Press the button A to draw a helix on the LED screen, and press button B to eliminate the helix as the same way:

## 26.2. Principle#

1. Draw a line of n units and turn left with 90 degrees.

2. Draw a line of n units and turn left with 90 degrees.

3. Again with the first step.

Steps 1 and 2 here can be controlled by a loop block in twice, then use a loop in the outermost to increase the value of n. The more the number of outer loops, the larger the graph will be.

In addition, we also need to draw and clear graphics. The principle is also very simple. We only need to adjust the brightness of the brush. When drawing, the brightness is 128. When clearing the graphics, set the brightness to 0, and then the brush follows the same route. Go again and the graphics will be cleared.

1.Go to MakeCode editor: https://makecode.microbit.org/ to create a new project.

2.Click “Advanced” to see more choices and click “Extensions”.

3.Click microturtle to add it in the new project we just created.

4.You can see a new item-turtle in the drawer now.

## 26.4. Code#

Draw a Helix function

1.Create a function and name it as Helix

2.Choose the home brick in the turtle drawer and set it in the middle of the screen.

3.Choose the pen down brick and set it down each time when the function is executed.

4.Create a variable and name it in n to indicate the length of the line segment.

5.Drag in a module for the value from 0 to x from the loop category, and change it to n from 0 to 4, which means looping 5 times. Each loop assigns one of the 5 values from 0 to 4 to the variable n.

6.Drag in a loop x times module and change to loop twice to draw two line segments with length n + 1.

7.Drag in a forward x steps module from the turtle category and change it to forward n + 1 steps, which means to move forward n+1 steps, that is, draw a line of length n+1, because n starts from 0, you need to +1 here to make it start at 1.

8.Drag a turn right module from the turtle category, which means to rotate 90 degrees to the right. Here you can also select turn left, the direction is opposite.

Button response event

1.Add response events to buttons A and B respectively

2.When button A is pressed, drag in a set brightness module from the turtle category and change it to set brightness 128, and then use the luoxuanxian function.

3.When button B is pressed, drag in a set brightness module from the turtle category, change it to set brightness 0, and then use the luoxuanxian function, so that the effect of clearing the graphics can be achieved.