Line: 1 to 1 | ||||||||
---|---|---|---|---|---|---|---|---|
Python modules and timing | ||||||||
Line: 43 to 43 | ||||||||
angle = 30 # use 30 degrees as parameter value result = sin_deg(angle) # calculates the sin of "angle" degrees using our own sin_deg function print("sin(",angle,") = ",result) | ||||||||
Added: | ||||||||
> > | Plotting a function | |||||||
Changed: | ||||||||
< < | Let's try these ExerciseSheets#SecondSession Thereafter we will learn how to access hardware in Hardware Access GPIO | |||||||
> > | ![]() is the formula for a damped oscillator. In order to plot its shape, we can first define a function which calculates its value for a given x. After that, we call this function for as many points as we want to plot, and we print the x and damped_osc(x) values. from math import exp,sin def damped_osc(x): # calculates the damped # oscillator function return exp(-1/10)*sin(x) for i in range(500): # calculate 500 values print(i/10,damped_osc(i/10) # and print themWhen running the program, we can redirect the printed data to a file. On the PC, using CPython (python3) this is done as follows: python3 damped_osc.py > damped_osc.dat.We can however also run the code on the ESP32 and redirect the output to a file on the PC: ampy run damped_osc.py > damped_osc.datOnce we have the data in a file, we call gnuplot: gnuplot plot "damped_osc.dat" with lines ![]() Let's try these ExerciseSheets#SecondSession Thereafter, we will learn how to access hardware in Hardware Access GPIO | |||||||
-- ![]() Comments | ||||||||
Added: | ||||||||
> > |
|