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
Fork of Nucleo-Analog_read by
main.cpp
- Committer:
- dousape2
- Date:
- 2015-03-13
- Revision:
- 1:dc5a274adc7d
- Parent:
- 0:242976b62902
- Child:
- 2:eb5ee8191175
File content as of revision 1:dc5a274adc7d:
#include "mbed.h"
#define voltage 3300
#define mv(x) ((x*voltage)/0xFFFF)
AnalogIn analog_value(A0);
Serial pc(SERIAL_TX, SERIAL_RX);
DigitalOut led(LED1);
Ticker toggle_ticker;
int voltages =0;
bool start = true;
void toggle()
{
int meas;
meas = analog_value.read_u16(); // Converts and read the analog input value (value from 0.0 to 0xFFFF)
meas = mv(meas); // Change the value to be in the 0 to 3300 range
while(!pc.writeable());
led= !led;
if (meas > voltages ) { // If the value is greater than 2V then switch the LED on
start = true;
}
if(start) {
printf("%d\n", meas);
}
}
void flushSerialPort()
{
while(pc.readable())
pc.getc();
return;
}
int main()
{
int prijData=0;
int Data1=0;
float Data2=0;
pc.baud(115200);
toggle_ticker.detach();
toggle_ticker.attach(&toggle, 0.01);
printf("\nAnalogIn example, data (numbers) are in mV.\n");
while(1) {
prijData=pc.scanf("%d %f",&Data1,&Data2);
if(prijData==2) {
//pc.printf()
if(Data1==1) {
toggle_ticker.detach();
toggle_ticker.attach(&toggle, Data2);
} else if(Data1==2) {
toggle_ticker.detach();
} else if(Data1==3) {
voltages=(int)Data2;
start = false;
}
} else {
while(!pc.writeable());
printf("HELP - MENU\n");
while(!pc.writeable());
printf("Data send to PC (numbers) are in mV.\n");
while(!pc.writeable());
printf("Set data exactly.\n");
while(!pc.writeable());
printf("Write to console: \"xx yy\", where xx is a code of seting and yy his value.\n");
while(!pc.writeable());
printf("01 y.yyy - set period[s] to send data to PC and start reading value, example:01 0.01\n");
while(!pc.writeable());
printf("02 0 - stop reading value example:02 0\n");
while(!pc.writeable());
printf("03 yyyy - Wait for minimum voltage[mV] (to 3299) and send data example:03 2000\n");
while(!pc.writeable());
printf("end HELP\n");
flushSerialPort();
}
// wait(0.2); // 200 ms
}
}
