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.
Diff: main.cpp
- Revision:
- 0:3b35413050ff
- Child:
- 1:5c7d8d760ece
diff -r 000000000000 -r 3b35413050ff main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Aug 04 09:56:53 2011 +0000
@@ -0,0 +1,50 @@
+#include "mbed.h"
+#include "semaphore.h"
+
+Ticker printer1;
+semaphore printSem;
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+
+volatile int sharedVariable;
+
+#define SEM_ENABLE 1
+
+void print1()
+{
+#if SEM_ENABLE==1
+ if(semPend(&printSem, 5) == SEM_ERR)
+ return;
+#endif
+
+ sharedVariable++;
+
+#if SEM_ENABLE==1
+ semPost(&printSem);
+#endif
+}
+
+int main()
+{
+ sharedVariable = 0;
+ semInit(&printSem, 1);
+ printer1.attach(&print1, 0.25);
+
+ while(1)
+ {
+#if SEM_ENABLE==1
+ semPend(&printSem, 10000);
+#endif
+
+ printf("\nfirst val = %d\n",sharedVariable);
+ sharedVariable++;
+ wait(1);
+ printf("second val = %d\n",sharedVariable);
+
+#if SEM_ENABLE==1
+ semPost(&printSem);
+#endif
+
+ wait(1);
+ }
+}
\ No newline at end of file