Library untuk Sensor APi UVtron

Files at this revision

API Documentation at this revision

Comitter:
hisyamfs
Date:
Fri Jun 14 15:19:19 2019 +0000
Commit message:
Library untuk Uvtron

Changed in this revision

Uvtron.cpp Show annotated file Show diff for this revision Revisions of this file
Uvtron.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Uvtron.cpp	Fri Jun 14 15:19:19 2019 +0000
@@ -0,0 +1,51 @@
+#include "Uvtron.h"
+
+Uvtron::Uvtron(PinName a) : _a(a)
+{
+        Counter=0;
+        PrevCounter=0;
+        NextCounter=0;
+        Flag=0;
+        _a.mode(OpenDrain);
+        _a.rise(this, &Uvtron::Count);
+}
+
+void Uvtron::Count()
+{
+        Counter++;
+}
+
+void Uvtron::Read()
+{
+    
+        PrevCounter = NextCounter;
+        NextCounter = Counter;
+
+    
+    if(NextCounter>(PrevCounter+1)&&Flag==0)
+    {
+            Flag=1;
+            Counter=0;
+    }
+    else if (NextCounter==PrevCounter&&Flag==1)
+    {
+            Flag=0;
+    }
+}
+
+void Uvtron::UVScan()
+{
+        PrevCounter = NextCounter;
+        NextCounter = Counter;
+    
+        if((NextCounter>PrevCounter) && (FlagScan==0)){
+                        FlagScan = 1;
+                        Counter = 0;
+        }
+        else{
+                //FlagScan = 0;
+        }
+}
+
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Uvtron.h	Fri Jun 14 15:19:19 2019 +0000
@@ -0,0 +1,26 @@
+#ifndef UVTRON_H
+#define UVTRON_H
+
+#include "mbed.h"
+
+class Uvtron
+{
+public:
+    // Constructor
+    Uvtron(PinName a);
+
+    unsigned int Counter, PrevCounter, NextCounter;
+    unsigned char Flag;
+    unsigned char FlagScan;
+
+    void Count();
+    void Read();
+    void UVScan();
+
+private:
+    InterruptIn _a;
+  unsigned char i;
+};
+
+#endif
+