Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
4_Pwm
Wiki-Seite
Gehe auf die Lehrerbox/PE/TINF und kopiere den Inhalt der Datei program-wiki.txt
auf IHRE EIGENE Wiki-Seite und ändere bzw. erweitere die entsprechenden Programme bzw. Textteile.
Diese Programme wurden im Mbed-Simulator geschrieben und getestet.
Lektion: bsp_Pwm
Programmbeschreibung:
Änderungen:
Datum:
A1_Lekt4_bsp_Pwm.cpp
#include "mbed.h" //BusOut myleds(D2,D3,D6,D9,D11,D12,A6,D13); //duty cycle = pulsewidth x 100 / period //default periodendauer 20ms, default pulsweite 0 /* hello pwm beispiel //https://os.mbed.com/docs/mbed-os/v5.14/apis/pwmout.html bsp: 4 second period Timer 1 2 second period Timer 16 1 second period Timer 15 2 second pulse (on) 3 second pulse (on) 0.5 second pulse (on) 1 second pulse (on) //new: //BusOut myleds(D0,D3,D6,D9,D11,D12,A1,A5); PwmOut led1(D0); // Timer 1 PwmOut led3(D3); // Timer 1 PwmOut led15(A1); // Timer 15 auch A2 - ext. Led PwmOut led16(A5); // Timer 16 auch D5-SCL - ext. Led int main() { // specify period first, then everything else led1.period(4.0f); // 4 second period Timer 1 led15.period(1.0f); // 1 second period Timer 15 led16.period(2.0f); // 2 second period Timer 16 led1.pulsewidth(2); // 2 second pulse (on) led3.pulsewidth(3); // 3 second pulse (on) led15.pulsewidth(0.5); // 0.5 second pulse (on) led16.pulsewidth(1); // 1 second pulse (on) while(1){}; } */ PwmOut led1(D0); PwmOut led2(D3); PwmOut led3(A1); PwmOut led4(A5); void pwm1(); void pwm2(); void pwm3(); void pwmbsp1(); int main() { /* led4.period(4.0f); //4 second period //led4.write(0.50f); //50% duty cycle, relative to period //led4=0.5f; //shorthand for led.write() led4.pulsewidth(2); //alternative to led.write, set duty cycle time in seconds */ //pwm1(); //pwm2(); //pwm3(); pwmbsp1(); while(1) { } } void pwmbsp1() { led1.period(4.0f); led3.period_ms(1000.0f); led4.period(2); //DC = pulsewidth*100/period led1.pulsewidth(2); led2.pulsewidth(3); led3.pulsewidth(0.50f); led4.pulsewidth(1); } void pwm3() { led3.period_ms(20.0f); led3.pulsewidth_ms(5); } void pwm2() { led2.period_ms(20.0f); // 20 milli second period led2.write(0.25f); // 25% duty cycle } void pwm1() { led1=0.25f; }