![](/media/cache/profiles/23d3743ad75e4470e7ff7129351a9541.jpg.50x50_q85.jpg)
ELNC-6007-19W example developed in Lecture. Enabling interrupts from DigitalIn and serial port receiver.
Revision 0:4741f5b28fec, committed 2019-03-14
- 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 |
--- /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; + } + } +}
--- /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