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.
Arduino.cpp
- Committer:
- ruke1ire
- Date:
- 2018-04-07
- Revision:
- 0:d93ce07131fc
- Child:
- 1:d96590319bcf
File content as of revision 0:d93ce07131fc:
#include "mbed.h" #include "Arduino.h" Arduino::Arduino(PinName tx, PinName rx) : _tx(tx), _rx(rx){ _arduino.baud(9600); } void Arduino::_sendCommand(char com){ _arduino.clc(); _arduino.printf("&c", com); } int Arduino::_recieveData(){ char value[100]; int index=0; char ch; do { if (_arduino.readable()) // if there is an character to read from the device { ch = _arduino.getc(); // read it if (index<99) // just to avoid buffer overflow value[index++]=ch; // put it into the value array and increment the index } } while (ch!='\n'); // loop until the '\n' character value[index]='\x0'; // add un 0 to end the c string return atoi(value); } int Arduino::getLdrY(){ _sendCommand('y'); return _recieveData(); } int Arduino::getLdrX(){ _sendCommand('x'); return _recieveData(); } int Arduino::getColor(){ _sendCommand('c'); return _recieveData(); } int Arduino::getOrientation(){ _sendCommand('a'); return _recieveData(); }