A NUCLEO-F446RE kártyára beépített LED1 fényerejének (PWM kitöltés) vezérlése a soros porton küldött karakterekkel (1: 1 % , 5: 50%, 9: 99%)

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
cspista
Date:
Tue Oct 12 17:16:36 2021 +0000
Commit message:
Final version

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Oct 12 17:16:36 2021 +0000
@@ -0,0 +1,27 @@
+#include "mbed.h"
+
+PwmOut myled(LED1);         // PA_5, a beépített LED
+Serial pc(USBTX, USBRX);    // tx, rx aoros terminál a PC-hez
+
+int main() {
+    pc.baud(115200);        // Adatsebesség beállítása
+    myled.period_ms(20);    // Periódus = 20 ms
+    myled.write(1.0);       // LED kezdetben kikapcsolva
+    
+    while(1) {
+        char c = pc.getc(); // Beolvasunk egy karaktert
+        if(c=='1') {
+            myled = 0.01f;  // LED 1 % kitöltéssel
+            pc.printf("Duty cycle = 0.01\r\n");
+        }
+        else if(c=='5') {   // LED 50 % kitöltéssel
+            myled = 0.5f;
+            pc.printf("Duty cycle = 0.5\r\n");        
+        }
+        else if(c=='9') {
+            myled = 0.99f;   //LED 99 % kitöltéssel
+            pc.printf("Duty cycle = 0.99\r\n");            
+        }        
+        wait(0.2);
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Oct 12 17:16:36 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file