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.
main.cpp
00001 #include "mbed.h" 00002 #include "USBHostSerial.h" 00003 00004 DigitalOut led(LED1); 00005 DigitalOut led2(LED2); 00006 DigitalOut led3(LED3); 00007 DigitalOut led4(LED4); 00008 00009 Serial pc(USBTX, USBRX); 00010 int chronos_answer[10] ; 00011 00012 void serial_task(void const*) 00013 { 00014 USBHostSerial serial; 00015 00016 00017 while(!serial.connect()) 00018 Thread::wait(500); 00019 00020 serial.baud(115200) ; 00021 00022 pc.printf("chronos init ...\n") ; 00023 00024 serial.putc(0xff) ; 00025 serial.putc(0x07) ; 00026 serial.putc(0x03) ; 00027 pc.printf("chronos init completed ...\n") ; 00028 00029 00030 while(1) { 00031 00032 // send read request to chronos 00033 serial.putc(0xFF); 00034 serial.putc(0x08); 00035 serial.putc(0x07); 00036 serial.putc(0x00); 00037 serial.putc(0x00); 00038 serial.putc(0x00); 00039 serial.putc(0x00); 00040 Thread::wait(15); 00041 00042 00043 // put received characters on an array 00044 int i = 0 ; 00045 while (serial.available()) { 00046 int c_in = serial.getc() ; 00047 chronos_answer[i++] = c_in ; 00048 } 00049 int button = chronos_answer[3] ; 00050 if(button != 255) { 00051 printf("Button received : %d\n", button ) ; 00052 switch(button) { 00053 case 18 : // * button 00054 led2 = 1 ; 00055 led3 = 0 ; 00056 led4 = 0 ; 00057 break ; 00058 case 50 : // up button 00059 led2 = 0 ; 00060 led3 = 1 ; 00061 led4 = 0 ; 00062 break ; 00063 case 34 : // # button 00064 led2 = 0 ; 00065 led3 = 0 ; 00066 led4 = 1 ; 00067 break ; 00068 00069 } 00070 } 00071 00072 00073 Thread::wait(50); 00074 00075 } 00076 } 00077 00078 int main() 00079 { 00080 Thread serialTask(serial_task, NULL, osPriorityNormal, 256 * 4); 00081 while(1) { 00082 led=!led; 00083 Thread::wait(500); 00084 } 00085 }
Generated on Tue Jul 19 2022 17:26:53 by
1.7.2