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:
- sangrit
- Date:
- 2018-04-07
- Revision:
- 1:d96590319bcf
- Parent:
- 0:d93ce07131fc
File content as of revision 1:d96590319bcf:
#include "mbed.h" #include "Arduino.h" Arduino::Arduino(PinName tx, PinName rx) : _arduino(tx,rx){ _arduino.baud(9600); } void Arduino::sendCommand(char com){ //_arduino.clc(); _arduino.printf("&c", com); } int Arduino::receiveData(){ 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 this->receiveData(); } int Arduino::getLdrX(){ sendCommand('x'); return receiveData(); } int Arduino::getColor(){ sendCommand('c'); return receiveData(); } int Arduino::getOrientation(){ sendCommand('a'); return receiveData(); }