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.
Dependencies: mbed
Diff: main.cpp
- Revision:
- 3:29a231eba2e0
- Parent:
- 2:10add9ee8c4b
--- a/main.cpp Sun Mar 22 14:53:35 2015 +0000
+++ b/main.cpp Tue May 12 08:56:09 2015 +0000
@@ -4,7 +4,7 @@
* @version V0.1
* @date 09-March-2015
* @brief Read value from pins and write it to serial.
-* It could be set some settings through serial.
+* Some settings can be set through serial.
* Serial speed is set to 115200.
***********************************************************************************/
@@ -25,15 +25,15 @@
/* Function prototypes -----------------------------------------------------------*/
/* Variables ---------------------------------------------------------------------*/
-int pin =0; //pins to compare and start print
-int vypis =0; // which output will be provided
-bool start = true; // if true it print value to serial
+int pin =0;
+int printout =0;
+bool start = true;
//mbed - initialization of peripherals
PortIn myIOs(PortC, 0xFFFF); // PC_all
-Serial pc(SERIAL_TX, SERIAL_RX); // inicialize Serial to connect to PC
-Ticker toggle_ticker; // inicialize ticker
-DigitalOut led(LED1); // inicialize LED
+Serial pc(SERIAL_TX, SERIAL_RX); // initialize Serial to connect to PC
+Ticker toggle_ticker; // initialize ticker
+DigitalOut led(LED1); // initialize LED
/* Functions----------------------------------------------------------------------*/
@@ -47,14 +47,14 @@
void toggle()
{
int meas,z;
- meas=myIOs.read(); // read pins
+ meas=myIOs.read(); // read pins
- led= !led; //blink led
- if (meas == pin ) { // If the value is as we want
- start = true; //start send data to Serial
+ led= !led; //blink led
+ if (meas == pin ) { // If the value is as we want
+ start = true; //start send data to Serial
}
if(start) {
- if(vypis==1) { // write value in bin
+ if(printout==1) { // write value in bin
while(!pc.writeable());
for (z =32768; z > 0; z >>= 1) {
while(!pc.writeable());
@@ -62,16 +62,16 @@
}
while(!pc.writeable());
pc.printf("\n");
- } else if(vypis==2) { // write value in decimal
+ } else if(printout==2) { // write value in decimal
while(!pc.writeable());
pc.printf("%d\n", meas);
- } else if(vypis==3) { // write value in oct
+ } else if(printout==3) { // write value in oct
while(!pc.writeable());
pc.printf("%o\n", meas);
- } else if(vypis==4) { // write value in hex
+ } else if(printout==4) { // write value in hex
while(!pc.writeable());
pc.printf("%x\n", meas);
- } else { // write value in all options
+ } else { // write value in all options
while(!pc.writeable());
pc.printf("DEC: %d, HEX: %x, OCT: %o, BIN: ", meas,meas,meas);
for (z =32768; z > 0; z >>= 1) {
@@ -86,7 +86,7 @@
/***********************************************************************************
* Function Name : flushSerialPort.
-* Description : Serial flush rountine.
+* Description : Serial flush routine.
* Input : None.
* Output : None.
* Return : None.
@@ -107,22 +107,20 @@
***********************************************************************************/
void menu()
{
- while(!pc.writeable()); // wait to be serial available for sending data
+ while(!pc.writeable()); // wait for the serial to be available for sending data
pc.printf("HELP - MENU\n");// send text to serial
while(!pc.writeable());
- pc.printf("Data send to PC is in dec format.\n");
+ pc.printf("Data to PC are in dec format.\n");
while(!pc.writeable());
- pc.printf("Set data exactly.\n");
+ pc.printf("Input format: \"xx yy\", where xx is the setting and yy is the value.\n");
while(!pc.writeable());
- pc.printf("Write to console: \"xx yy\", where xx is a code of seting and yy his value.\n");
+ pc.printf("01 y.yyy - set period [seconds] to send data to PC and start reading value, example: 01 0.01\n");
while(!pc.writeable());
- pc.printf("01 y.yyy - set period[s] to send data to PC and start reading value, example:01 0.01\n");
- while(!pc.writeable());
- pc.printf("02 0 - stop reading value, example:02 0\n");
+ pc.printf("02 0 - stop reading value, example: 02 0\n");
while(!pc.writeable());
- pc.printf("03 yyyy - Wait for pin to get to log.1. yyyy write in dec example:03 2000\n");
+ pc.printf("03 yyyy - Wait for pin to get to high level. yyyy write in decimal, example: 03 2000\n");
while(!pc.writeable());
- pc.printf("04 yy - print yy: 00-default all, 01-bin, 02-dec, 03-oct, 04-hex, example:04 00\n");
+ pc.printf("04 yy - print format yy: 00-default all, 01-bin, 02-dec, 03-oct, 04-hex, example: 04 00\n");
while(!pc.writeable());
pc.printf("end HELP\n");
}
@@ -148,42 +146,42 @@
pc.printf("\nLogic sond.\n");
menu(); //print menu
- toggle_ticker.detach(); // do NOT call function
- toggle_ticker.attach(&toggle, 1); // 1 second was passed, call function toggle
+ toggle_ticker.detach(); // detach all functions from ticker
+ toggle_ticker.attach(&toggle, 1); // call function toggle every single second
while(1) {
//accepted data from serial
prijData=pc.scanf("%d",&Data1); // read number from serial
- if(prijData==1 && (Data1>=1 && Data1<=3)) { // test if number was read and it is between 1 and 3
+ if(prijData==1 && (Data1>=1 && Data1<=3)) { // test if number was read and if it's between 1 and 3
prijData=pc.scanf("%f",&Data2); // read float number from serial
if(prijData==1) {
prijData=2; // set variable to set measure of values
} else {
- flushSerialPort(); // iscard data from serial
+ flushSerialPort(); // clear serial port, discard all data in the buffer
prijData=0; // set variable to print menu
}
} else {
- flushSerialPort(); // discard data from serial
+ flushSerialPort(); // clear serial port, discard all data in the buffer
prijData=0; // set variable to print menu
}
if(prijData==2) {
if(Data1==1) {
- toggle_ticker.detach(); // do NOT call function
+ toggle_ticker.detach(); // detach all functions from ticker
toggle_ticker.attach(&toggle, Data2); // Data2 seconds was passed, call function toggle
} else if(Data1==2) {
- toggle_ticker.detach(); // do NOT call function
+ toggle_ticker.detach(); // detach all functions from ticker
} else if(Data1==3) {
- pin=(int)Data2; //set variables, which are use in toggle
+ pin=(int)Data2; //set variables, which are used in toggle
start = false;
} else if(Data1==4) {
- vypis=(int)Data2; //set variables to set printf, which are use in toggle
+ printout=(int)Data2; //set variables to set printf, which are used in toggle
}
} else {
- toggle_ticker.detach(); // do NOT call function
- menu(); //print menu
- flushSerialPort(); // discard data from serial
+ toggle_ticker.detach(); // detach all functions from ticker
+ menu(); // print menu
+ flushSerialPort(); // clear serial port, discard all data in the buffer
}
}
}