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: C027_Support C12832 LM75B MMA7660 MbedSmartRest mbed-rtos mbed
Fork of MbedSmartRestMain by
io.cpp
- Committer:
- vwochnik
- Date:
- 2014-02-14
- Revision:
- 12:beb64aa0da86
- Child:
- 14:56da550a1baa
File content as of revision 12:beb64aa0da86:
#include "io.h"
#include "rtos.h"
#define S_INIT 0
#define S_OPEN 1
#define S_GONE 2
void thread_callback(void const*);
// adjust pin numbers
LM75B tempSensor(p28, p27);
MMA7660 accSensor(p28, p27);
DigitalIn button(p14);
Thread worker(thread_callback);
uint8_t tempState = S_INIT;
uint8_t accState = S_INIT;
uint32_t count = 0;
float temperature()
{
if ((tempState == S_INIT) && (tempSensor.open()))
tempState = S_OPEN;
else
tempState = S_GONE;
if (tempState == S_OPEN)
return tempSensor.temp();
return 0.0;
}
acceleration_t acceleration()
{
float data[3];
acceleration_t ret = { 0.0, 0.0, 0.0 };
if ((accState == S_INIT) && (accSensor.testConnection()))
accState = S_OPEN;
else
accState = S_GONE;
if (accState == S_OPEN) {
accSensor.readData(data);
ret.x = data[0];
ret.y = data[1];
ret.z = data[2];
}
return ret;
}
uint32_t counter()
{
return count;
}
void thread_callback(void const*)
{
bool pressed = false;
while (true) {
if ((!pressed) && (button))
count++;
pressed = button;
}
}
