Fotoresistenza e Capacità in serie

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
Marsep3
Date:
Sat Oct 29 09:51:51 2016 +0000
Commit message:
valutare luminosit? dell'ambiente tramite uso di un condensatore e una fotoresistenza in serie

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sat Oct 29 09:51:51 2016 +0000
@@ -0,0 +1,47 @@
+#include "mbed.h"
+#define soglia 1000
+Serial pc(USBTX,USBRX);
+unsigned int RCtime();
+unsigned int photoR;
+DigitalOut out(D6);
+DigitalInOut sens(D4);
+
+int main()
+{
+    pc.printf("ADC data values...\n\r");
+    while (1) {
+        photoR = RCtime();
+        
+        if(photoR == 30000){
+            pc.printf("Nothing connected...\n\r");
+            }
+        else {
+            pc.printf("RC time reading = ");
+            pc.printf("%u\n\r",photoR);
+            
+            if(photoR>soglia){
+                out=1;
+                }
+            else{
+                out=0;
+                 }
+              }
+    wait(0.1);
+                }
+    }
+
+unsigned int RCtime()
+{
+    int reading = 0;
+    sens.output();
+    sens=0;
+    wait_ms(10);
+    sens.input();
+    while(sens == 0){
+        reading++;
+        if(reading == 30000){
+            break;
+            }
+        }
+    return reading;
+    }
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sat Oct 29 09:51:51 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/9bcdf88f62b0
\ No newline at end of file