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: FreeRTOS mbed MMA7660 LM75B
Diff: main.cpp
- Revision:
- 2:4e4fa763799a
- Parent:
- 1:1990d6e600c2
- Child:
- 3:9ec3ee7cf0bc
--- a/main.cpp Tue Aug 22 02:04:17 2017 +0000
+++ b/main.cpp Sun Oct 01 03:33:48 2017 +0000
@@ -1,57 +1,50 @@
#include "mbed.h"
#include "FreeRTOS.h"
#include "task.h"
-#include "C12832.h"
#include "LM75B.h"
+#include "MMA7660.h"
DigitalOut led1(LED1);
DigitalOut led2(LED2);
DigitalOut led3(LED3);
DigitalOut led4(LED4);
-C12832 lcd(p5, p7, p6, p8, p11);
LM75B sensor(p28,p27);
+MMA7660 mma(p28,p27);
-void vHello(void *pvParameters);
-void vGbye(void *pvParameters);
+void vtemperature(void *pvParameters);
+void vshock(void *pvParameters);
int main() {
- portBASE_TYPE task1rc;
- portBASE_TYPE task2rc;
-
+ // Sensor connection check
if (sensor.open()){
- printf("LM75B temperature sensor detected, proceeding with program.\n");
+ printf("LM75B temperature sensor detected.\n");
}
else {
printf("LM75B sensor not detected!\n");
- return;
+ return 1;
}
- task1rc = xTaskCreate(vHello, "HELLO", configMINIMAL_STACK_SIZE, (void*)"name1", configMAX_PRIORITIES-2, NULL);
+ if (mma.testConnection()){
+ printf("MMA7660 accelerometer sensor detected.\n");
+ }
+ else {
+ printf("MMA7660 sensor not detected!\n");
+ return 1;
+ }
+ printf("All sensors acounted for. Proceeding with program.\n");
- task2rc = xTaskCreate(vGbye, "BYE", configMINIMAL_STACK_SIZE, (void*)"name2", configMAX_PRIORITIES-1, NULL);
+ // Task 1 will read and print temperature data
+ task1rc = xTaskCreate(vtemperature, "HELLO", 255, (void*)"TASK1", configMAX_PRIORITIES-2, NULL);
+
+ // Task 2 will read accelerometer data
+ task2rc = xTaskCreate(vshock, "BYE", 255, (void*)"TASK2", configMAX_PRIORITIES-1, NULL);
vTaskStartScheduler();
- if (task1rc == pdPASS){
- led1 = 1;
- wait(0.5);
- led1 = 0;
- }
- else{
- led1 = 0;
- }
-
- if (task2rc == pdPASS){
- led2 = 1;
- wait(0.5);
- led2 = 0;
- }
- else{
- led2 = 0;
- }
-
for (;;){
+ /*If the tasks fail to initialize/run properly, led3 and led4 will
+ toggle on/off to indicate the failure. */
led3 = 1;
led4 = 1;
wait(0.5);
@@ -59,32 +52,39 @@
led4 = 0;
wait(0.5);
};
+
}
-void vHello(void *pvParameters)
+void vtemperature(void *pvParameters)
{
char *ptr = 0;
+ float tdata = 0.0;
ptr = (char *)pvParameters;
+ int time = 0;
for(;;)
{
- printf("Hello %s!\n", ptr);
- printf("Current temperature: %s\n", (float)sensor.temp());
+ tdata = (float)sensor.temp();
+ printf("sample %i: %.3f c\n", time, tdata);
led1 = !led1;
+ time++;
vTaskDelay(300);
}
}
-void vGbye(void *pvParameters)
+void vshock(void *pvParameters)
{
char *ptr = 0;
+ float accel_z = 0.0;
ptr = (char *)pvParameters;
+ int time = 0;
for(;;)
{
- printf("Goodbye %s!\n", ptr);
+ accel_z = mma.z();
+ printf("sample %i: %.3f g\n", time, accel_z);
led2 = !led2;
- wait(0.5);
+ time++;
vTaskDelay(300);
}
}
\ No newline at end of file