Line: 1 to 1 | |||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Exercises | |||||||||||||||||||||||||
Line: 6 to 6 | |||||||||||||||||||||||||
First exercise session:A bit of programming | |||||||||||||||||||||||||
Changed: | |||||||||||||||||||||||||
< < | Connect your ESP32 to the PC using the micro USB cable and start thonny. Locate the shell window and check if you see the PEPL prompt ">>>". If not, try to press <enter>. Make sure the shell window has the input focus. If this does not work, press the stop button. If this also doesn't help, press the reset button on the ESP32 CPU board. | ||||||||||||||||||||||||
> > | Connect your ESP32 to the PC using the micro USB cable and start thonny. Locate the shell window and check if you see the REPL prompt ">>>". If not, try to press <enter>. Make sure the shell window has the input focus. If this does not work, press the stop button. If this also doesn't help, press the reset button on the ESP32 CPU board. | ||||||||||||||||||||||||
Playing with REPL
| |||||||||||||||||||||||||
Line: 46 to 46 | |||||||||||||||||||||||||
Write a script that prints "Hello World!" forever. You can stop the program with the red Stop button. Write a program that prints "Hello World!" 7 times. Do this using a while loop and in a second program, using a for loop, Which of the programs is more elegant? | |||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||
> > | Too easy? Calculate the Fibonacci numbersThe Fibonacci numbers are defined as follows:
| ||||||||||||||||||||||||
This is the end of the first exercise sessionSecond exercise sessionMicroPython modules | |||||||||||||||||||||||||
Changed: | |||||||||||||||||||||||||
< < | Modify the loop program in such a way that "Hello World!" is printed only every second. Import the utime module and make the program sleep for 1s after each print statement. | ||||||||||||||||||||||||
> > | Modify the loop program in such a way that "Hello World!" is printed only every second. Import the time module and make the program sleep for 1s after each print statement. | ||||||||||||||||||||||||
Import the sin function and the value of pi from the math module | |||||||||||||||||||||||||
Line: 64 to 71 | |||||||||||||||||||||||||
Create a sin_deg function which takes angles in units of degrees instead of radians. Print the angles and the sin values for 36 equidistant angle values. You may copy/paste the result to a new editor window in thonny and save them to a file on the PC. Then you can plot the function using gnuplot. | |||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||
> > |
| ||||||||||||||||||||||||
![]() | |||||||||||||||||||||||||
Changed: | |||||||||||||||||||||||||
< < | Calculating the throwing parabola | ||||||||||||||||||||||||
> > | Too easy? Calculate the throwing parabola | ||||||||||||||||||||||||
Changed: | |||||||||||||||||||||||||
< < | If the above is too simple for you, you may try to calculate the throwing parabola. Let's say, a stone is thrown at a speed of 30m/s and an angle of 30° with respect to ground. Calculate the trajectory of the stone until it hits the ground. You way define a function trajectory, taking initial speed, the angle and the time resolution for which you want to calculate the stone positions. | ||||||||||||||||||||||||
> > | If the above is too simple for you, you may try to calculate the throwing parabola. Let's say, a stone is thrown at a speed of 30m/s and an angle of 30° with respect to ground. Calculate the trajectory of the stone until it hits the ground. You may define a function trajectory, taking as parameters the initial speed, the angle and the time resolution for which you want to calculate the stone positions. | ||||||||||||||||||||||||
v_hor = v_initial * cos(angle) | |||||||||||||||||||||||||
Line: 85 to 94 | |||||||||||||||||||||||||
tp_10 is the trajectory for 10 degrees. tp_45 is the trajectory for 45 degrees. | |||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||
> > |
Plotting is done as described above. When plotting several data files, use
replot "data_file.dat" with linesin order to avoid deleting the previous plot. | ||||||||||||||||||||||||
End of the second exercise session | |||||||||||||||||||||||||
Line: 102 to 117 | |||||||||||||||||||||||||
Use the function to implement a program that blinks an SOS: 3 short pulses, followed by 3 long pulses, followed by 3 short pulses, followed by a 2s pause. You may use a 200 ms delay for the short pulses and 700 ms delay for the long ones.
Reading the pushbutton | |||||||||||||||||||||||||
Changed: | |||||||||||||||||||||||||
< < | Write a program that reads the push button state ever 100 ms and prints its state (pressed or released) | ||||||||||||||||||||||||
> > | Write a program that reads the push button state every 100 ms and prints its state (pressed or released) | ||||||||||||||||||||||||
Improve the program printing the state only when there was a state change. | |||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||
> > | Too easy? Change the light intensity on the LED using PWM | ||||||||||||||||||||||||
Changed: | |||||||||||||||||||||||||
< < |
Forth exercise session | ||||||||||||||||||||||||
> > | Write a program that linearly increases the light intensity of the user programmable LED using Pulse Width Modulation ( PWM![]() Fourth exercise session | ||||||||||||||||||||||||
Reading an analogue signal level from the slider potentiometer
| |||||||||||||||||||||||||
Changed: | |||||||||||||||||||||||||
< < |
| ||||||||||||||||||||||||
> > |
| ||||||||||||||||||||||||
Controlling the rgb LED ring | |||||||||||||||||||||||||
Changed: | |||||||||||||||||||||||||
< < | The LED ring consists of 7 WS2812B addressable and cascadable LEDs. Each rgb LED consists of 3 tiny single color LEDs emitting red, green and blue light. The color you finally see is the mixture between these color components. The MicroPython driver for this type of LED is called NeoPixel. ![]() | ||||||||||||||||||||||||
> > | The LED ring consists of 7 WS2812B addressable and cascadable LEDs. Each rgb LED consists of 3 tiny single color LEDs emitting red, green and blue light. The color you finally see is the mixture between these color components. The MicroPython driver for this type of LED is called NeoPixel. ![]() | ||||||||||||||||||||||||
Changed: | |||||||||||||||||||||||||
< < | Write a program trying to find out to which LED an LED number corresponds to. Where on the LED ring is LED0, LED1 ... Do this by lighting the LEDs one by one with only the red color component switched on. The green and blue are set to zero. | ||||||||||||||||||||||||
> > | Write a program trying to find out to which physical LED an LED number corresponds to. Where on the LED ring is LED0, LED1 ...? Do this by lighting the LEDs one by one with only the red color component switched on. The green and blue are set to zero. | ||||||||||||||||||||||||
Then change the color. Try all color combinations (31,0,0), (0,31,0), (0,0,31) but also (31,31,0), (31,0,31) ... Which colors do you get? You can further modify the colors by changing the intensity values. For example: (12,27,5) Play around trying to generate as many different colors as you like. You may have a look at the small project below and light the LEDs in the colors required by the project. | |||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||
> > | Too easy? Program the Color WheelWrite a program that shows all the colors of the color wheel on the LEDs of the rgb LED ring. The color on the LEDs will slowly change from red to yellow to green … to magenta to red. | ||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||
> > | ![]() | ||||||||||||||||||||||||
A small projectAs a small project, we are going to combine the reading of the ADC and the control of the rgb LED ring. As we saw, the ADC delivers values between 0 and 4095 (12 bits). We can divide this range in 7 slices, corresponding to the 7 LEDs in the ring. For the lowest slice, the top LED will be lit. Then we go clockwise around the ring: the next LED lit will be to the right of the first one. For the highest slice, the middle LED will be lit. | |||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||
> > | In a first version, write a program that prints the LED number corresponding to the signal level on the slider. Make sure you get a value between 0 and 7. Then light the LED you found with a single color (e.g. green) | ||||||||||||||||||||||||
Very often, the color indicates the signal level: For low signal levels, we use "cold" colors (blue, cyan) for higher levels we use "hot" colors (magenta, red, white). The color for the top LED will therefore be blue, the color for the middle LED will be white. Here is the color sequence: | |||||||||||||||||||||||||
Changed: | |||||||||||||||||||||||||
< < |
| ||||||||||||||||||||||||
> > |
| ||||||||||||||||||||||||
Here is the exercise sheet in odt format: | |||||||||||||||||||||||||
Line: 158 to 184 | |||||||||||||||||||||||||
| |||||||||||||||||||||||||
Added: | |||||||||||||||||||||||||
> > |
|