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.
Revision 0:77dba5d612e5, committed 2021-04-08
- Comitter:
- jhusnik
- Date:
- Thu Apr 08 16:32:55 2021 +0000
- Commit message:
- a
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.gitignore Thu Apr 08 16:32:55 2021 +0000 @@ -0,0 +1,4 @@ +.build +.mbed +projectfiles +*.py*
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/USB/usb.cpp Thu Apr 08 16:32:55 2021 +0000
@@ -0,0 +1,19 @@
+#include "usb.h"
+
+Serial PC(USBTX, USBRX, 9600);
+
+void Start(void){
+ PC.printf("\n\r Unos vrijednosti u rasponu 0 - 9:\n\r");
+ }
+
+float Unos(void){
+ char podatak = PC.getc();
+ PC.printf("%c\n\r", podatak);
+ int a;
+ float b;
+ a = podatak;
+ if ((a <= 57)&&(a >= 48 )){
+ b = (a - 48)/10.0;
+ }
+ return (b);
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/USB/usb.h Thu Apr 08 16:32:55 2021 +0000 @@ -0,0 +1,9 @@ +#ifndef USB_H +#define USB_H +#include "mbed.h" + +extern Serial PC; +float Unos(void); +void Start(void); + +#endif \ No newline at end of file
--- /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;
+ }
+ }
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-os.lib Thu Apr 08 16:32:55 2021 +0000 @@ -0,0 +1,1 @@ +https://github.com/ARMmbed/mbed-os/#cf4f12a123c05fcae83fc56d76442015cb8a39e9