mbed2_3_b_ii

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Robsonik16
Date:
Fri May 05 19:46:56 2017 +0000
Commit message:
a

Changed in this revision

kosz.txt Show annotated file Show diff for this revision Revisions of this file
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
diff -r 000000000000 -r da2fe761ec44 kosz.txt
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/kosz.txt	Fri May 05 19:46:56 2017 +0000
@@ -0,0 +1,20 @@
+// Blink until timeout.
+
+#include "mbed.h"
+
+Timeout timeout;
+DigitalOut led(LED1);
+
+int on = 1;
+
+void attimeout() {
+    on = 0;
+}
+
+int main() {
+    timeout.attach(&attimeout, 5);
+    while(on) {
+        led = !led;
+        wait(0.2);
+    }
+}
diff -r 000000000000 -r da2fe761ec44 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri May 05 19:46:56 2017 +0000
@@ -0,0 +1,115 @@
+#include "mbed.h"
+
+//------------------------------------
+// Hyperterminal configuration
+// 9600 bauds, 8-bit data, no parity
+//------------------------------------
+
+RawSerial pc(USBTX,USBRX,9600);
+
+DigitalOut led_green(LED1);
+DigitalOut led_red(LED2);
+
+
+
+Timeout LedTimeout;
+Ticker Sender;
+
+void LedOff()
+{
+    led_red=0;
+}
+
+int my_puts(char tab[],int size)
+{
+//retutn 0 if string is valid
+    bool StringIsValid=false;
+    for( int index=0; index<size; index++) {
+        if (tab[index]==NULL) {
+            StringIsValid = true;
+            break;
+        }
+    }
+    if(StringIsValid == false) {
+        LedTimeout.attach(&LedOff, 0.5);
+        led_red=1;
+        return(1);
+    }
+
+    for( int index=0; index<size; index++) {
+        if (tab[index]==NULL) {
+            pc.putc('\r');
+            while(!pc.writeable());
+            pc.putc('\n');
+            return(0);
+        }
+        while(!pc.writeable());
+        pc.putc(tab[index]);
+    }
+    return(0);
+}
+
+void hardbeatSend()
+{
+    static int count=0;
+    char tekst[25];
+    sprintf(tekst,"hardbeat number: %d \r\n", count );
+    //pc.printf("This program runs since %d seconds.\r\n", i);
+    my_puts(tekst,22);
+    count++;
+}
+
+char my_gets(char str[],int size)
+{
+    if (!pc.readable())return (NULL);
+    char c;
+    for(int index=0; index <size; index++) {
+        c=pc.getc();
+        pc.putc(c);
+        if ((c=='\r')||(c=='\n')) {
+            pc.putc('\r');
+            pc.putc('\n');
+            str[index]=NULL;
+            return (1);
+        }
+        str[index]=c;
+    }
+    LedTimeout.attach(&LedOff, 5);
+    led_red=1;
+    return (1);
+}
+
+int main()
+{
+
+
+    bool flag=false;
+
+    const char tekstSize = 7;
+    char tekst[tekstSize];
+    //my_puts("[2J",5);//clear console
+    //pc.putc('[2J');
+    pc.putc(27);
+    char init[] = "system start\r\n";
+    my_puts(init,tekstSize);
+    Sender.attach(&hardbeatSend,1);
+
+
+
+    while(1) {
+
+
+
+        if (my_gets(tekst,tekstSize)!=NULL) {
+            
+            my_puts(tekst,tekstSize);
+            if(strcmp(tekst,"on"))flag = true;
+            if(strcmp(tekst,"off"))flag = false;
+            if(strcmp(tekst,"toggle"))flag = !flag;
+            led_green =flag;
+        }
+
+    }
+}
+
+
diff -r 000000000000 -r da2fe761ec44 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri May 05 19:46:56 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed/builds/97feb9bacc10
\ No newline at end of file