ELNC-6007-19W example developed in Lecture. Enabling interrupts from DigitalIn and serial port receiver.

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
TheFella
Date:
Thu Mar 14 17:52:24 2019 +0000
Commit message:
Example for lecture class

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
diff -r 000000000000 -r 4741f5b28fec main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Mar 14 17:52:24 2019 +0000
@@ -0,0 +1,80 @@
+#include "mbed.h"
+
+#define ROWS 10
+#define COLS 10
+#define BUFSIZE 30
+#define TRUE    1
+#define FALSE   0
+
+PwmOut spk( p25 );
+DigitalIn pb1( p8 );
+DigitalIn pb2( p19 );
+DigitalIn pb3( p18 );
+
+Serial pc(USBTX, USBRX, 9600); 
+
+InterruptIn pb1Int( p8 );
+
+char buffer[ BUFSIZE ];
+char *ptr = buffer;
+char sentenceReady = FALSE;
+
+void serialISR()
+{
+    int index = 0;
+    if( pc.readable() )
+    {
+        char hold = pc.getc();
+        if( hold == '$' )
+        {
+            for( index = 0; index<BUFSIZE; index++)
+            {
+                buffer[ index ] = 0;
+            }
+            ptr = buffer;
+                
+        }
+        if( hold == '#' )
+        {
+            sentenceReady = TRUE;
+        }
+        *ptr = hold;
+        ptr++;
+        if( ptr >= &buffer[ BUFSIZE ] )
+        {
+            ptr = buffer;
+        }
+    }
+}
+
+
+void pb1ISR()
+{
+    int row = 0, col = 0;
+    for( row = 0; row< ROWS; row++ )
+    {
+        for( col = 0; col< COLS; col++ )
+        {
+            pc.printf("|_");            
+        }
+        pc.printf("\n\r");
+    }
+    
+}
+    
+int main() 
+{
+    pb1Int.rise( &pb1ISR );
+    pc.attach( &serialISR );
+    
+    while(1) 
+    {
+        //pc.printf(".\n\r");
+        //wait(0.5);      
+        if( sentenceReady )
+        {
+            pc.printf("%s", buffer);
+            sentenceReady = FALSE;
+        }
+    }
+}
diff -r 000000000000 -r 4741f5b28fec mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Mar 14 17:52:24 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file