Robert Labuz
/
mbed2_2_a
mbed2_2_a
Revision 0:a807bd13ba83, committed 2017-05-05
- Comitter:
- Robsonik16
- Date:
- Fri May 05 19:45:09 2017 +0000
- Commit message:
- a
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 Fri May 05 19:45:09 2017 +0000 @@ -0,0 +1,132 @@ +#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); + +//DigitalIn led_green_in(LED1); + +InterruptIn user_button(USER_BUTTON); + +float delay_on = 0.2; +float delay_off = 1.0; + +void button_pressed() +{ + delay_on = 0.1; + delay_off = 0.1; +} + +void button_released() +{ + delay_on = 0.2; + delay_off = 1.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) 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); +} + + +char *my_gets(char *str){ + if (!pc.readable())return (NULL); + char c; + for(int index=0;;index++){ + c =pc.getc (); + if ((c=='\r')||(c=='\n')){ + str[index]=NULL; + return (str); + } + str[index]=c; + } + +} + +int main() +{ + //user_button.rise(&button_pressed); + //user_button.fall(&button_released); + + //pc.format(8, Serial::None, 1); + + //pc.baud(9600); + + bool flag=false; + char text[15]; + text[0]='0'; + text[1]='1'; + text[2]='2'; + text[3]='3'; + text[4]='4'; + text[5]='5'; + text[6]='6'; + text[7]=0; + + while(1) { + + //pc.printf("This program runs since %d seconds.\r\n", i); + + + //wait(1); + + + + + text = my_gets(text); + if (text!=NULL) my_puts(text,size); + + /* + if (pc.readable()){ + char c =pc.getc (); + pc.putc(c); + if (c == 's')flag = true; + if (c == 'r')flag = false; + if (c == 't')flag=!flag; + led_green =flag; + int size = 8; + puts2(text,size); + //int puts(char *tab,int size){ + + } + + */ + + + /* + for(char a = 'a';a<='z';a++){ + pc.putc(a); + pc.putc('\r'); + pc.putc('\n'); + wait(0.1); + } + */ + } +} +
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri May 05 19:45:09 2017 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/mbed_official/code/mbed/builds/97feb9bacc10 \ No newline at end of file