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
main.cpp
00001 //TODO: dodati sd card logger 00002 //TODO: dodati conversion for sensors 00003 //TODO: Serial Read from LabView on start 00004 //TODO: PWM output 00005 00006 #include "mbed.h" 00007 #include "stdio.h" 00008 #include "string" 00009 00010 #define SAMPLE_RATE 0.01 00011 Serial pc(USBTX, USBRX); // tx, rx 00012 00013 Timer timer; 00014 AnalogIn a_input[] = {A0,A1,A2,A3,A4}; 00015 const int numberOfInputs=5; 00016 float analog_values[numberOfInputs]; 00017 00018 char buffer[100]; 00019 char temp[30]; 00020 void read_inputs(); 00021 void convert_inputs(); 00022 void send_results(); 00023 00024 void flushSerialBuffer(void) { char char1 = 0; while (pc.readable()) { char1 = pc.getc(); } return; } 00025 00026 int main() { 00027 timer.start(); 00028 flushSerialBuffer(); 00029 while(1){ 00030 if (timer.read() > SAMPLE_RATE) { 00031 read_inputs(); 00032 convert_inputs(); 00033 send_results(); 00034 timer.reset(); 00035 } 00036 } 00037 } 00038 void read_inputs(){ 00039 for (int i=0;i<numberOfInputs;i++){ 00040 analog_values[i]= a_input[i].read()*3.3; //convert to voltage 00041 } 00042 } 00043 void convert_inputs(){ 00044 for (int i=0;i<numberOfInputs;i++){ 00045 sprintf(temp,"%.3f",analog_values[i]); //convert float to string 00046 strcat(temp,"#"); //add delimiter 00047 strcat(buffer,temp); //concatenate buffer and new value 00048 } 00049 strcat(buffer,"?"); //end char 00050 } 00051 void send_results(){ 00052 pc.printf(buffer); //serial send buffer 00053 sprintf(buffer,"$"); //start char 00054 }
Generated on Thu Jul 14 2022 14:14:20 by
1.7.2