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.
Diff: main.cpp
- Revision:
- 0:77dba5d612e5
diff -r 000000000000 -r 77dba5d612e5 main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Apr 08 16:32:55 2021 +0000
@@ -0,0 +1,89 @@
+#include "mbed.h"
+#include "usb.h"
+
+DigitalOut R(PA_0);
+DigitalOut G(PA_1);
+DigitalOut B(PC_0);
+int t1 = 3;
+int t2 = 1;
+
+InterruptIn Pp(PA_4);
+Timer debounce;
+
+Ticker signalizacija;
+
+float DC = 0.9;
+PwmOut PWM(PC_7);
+
+class Flasher {
+public:
+ Flasher(PinName pin) : _pin(pin) {
+
+ _pin = 0;
+ }
+
+ void flash() {
+ _pin = !_pin;
+ }
+
+private:
+ DigitalOut _pin;
+};
+
+Flasher S(PA_8);
+
+void Sign(){
+ S.flash();
+ }
+
+void toggle (){
+ if (debounce.read_ms()>200){
+ R = 1; B = 0; G = 1;
+ int i = 0;
+ while(i<10){
+ G = !G;
+ i = i++;
+ wait (0.3);
+ }
+ R = 0; B = 0; G = 0;
+ }
+ debounce.reset();
+ }
+
+void Semafor(){
+ R = 1;
+ wait (t1);
+ R = 0;
+ B = 1;
+ wait(t2);
+ B = 0;
+ G = 1;
+ wait (t1);
+ B = 1;
+ wait (t2);
+ B = 0;
+ G = 0;
+ }
+
+int main(){
+
+ signalizacija.attach(&Sign, 1);
+
+ PWM.period(0.01);
+ PWM = DC;
+
+ debounce.start();
+ Pp.rise(&toggle);
+
+ Start();
+
+ while (1) {
+ Semafor();
+
+ if (PC.readable() == 1){
+ DC = Unos();
+ PC.printf("%f\n\r", DC);
+ PWM = DC;
+ }
+ }
+}