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: ComparatorIn mbed
Fork of ComparatorIn_demo by
Diff: main.cpp
- Revision:
- 0:e5deffde916d
- Child:
- 1:fb35e688f9f4
diff -r 000000000000 -r e5deffde916d main.cpp
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Wed Jun 05 18:07:02 2013 +0000
@@ -0,0 +1,51 @@
+#include "ComparatorIn.h"
+#include "mbed.h"
+
+DigitalOut myled(LED1); // Blue
+DigitalOut cmpled(LED2); // Green
+DigitalOut cmp_en (PTD5);
+AnalogIn cmp_lvl (PTB0);
+ComparatorIn compi(PTC8, NC); // light sensor comparator input
+
+// Comparator callback function
+void cmp_ISR(unsigned int cmp_ret)
+{
+ printf("\n%02X - Light sensor : %7.5f Volt - ",cmp_ret,cmp_lvl*3.3);
+ if ((cmp_ret & CMP_SCR_CFR_MASK)==CMP_SCR_CFR_MASK)
+ {
+ printf("<INT=Rising edge on HSCMP0>\n");
+ }
+ if ((cmp_ret & CMP_SCR_CFF_MASK)==CMP_SCR_CFF_MASK)
+ {
+ printf("<INT=Falling edge on HSCMP0>\n ");
+ }
+}
+
+
+
+int main()
+{
+ cmp_en = 1;
+
+ compi._callbackISR(&cmp_ISR); // Set comparator callback to cmp_ISR
+ compi.treshold(0x20); // Set copmarator threshold to 1.03V = 20 * 3.3V / 64
+
+ while(1)
+ {
+// printf("InP : %02X - InM : %02X - DACCR : %02X\n",(CMP0->MUXCR & 0x38)>>3,(CMP0->MUXCR & 0x07),(CMP0->DACCR & 0x3f));
+ printf("Light sensor : %7.5f Volt\n",cmp_lvl*3.3);
+ myled = 1;
+ wait(1);
+ myled = 0;
+ wait(0.2);
+ if (compi.status() == 0x01)
+ {
+ cmpled = 0;
+ }
+ else
+ {
+ cmpled = 1;
+ }
+ }
+}
+
