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:bee32ed0a6b4
- Child:
- 1:f4abb1d24a76
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Sat Nov 01 20:29:33 2014 +0000
@@ -0,0 +1,81 @@
+// Program.: Photo_LED
+// Version.: 1.0
+// Chip....: STM32F4xx
+// Date....: November 2014
+// Author..: UJ
+//-----------------------------------------------------------------------------
+
+// This program is a simple demonstration how a normal LED can be used as a
+// photo diode. The hardware platform I have used is the NUCLEO 411RE, but
+// the principle can be used with every modern CMOS-controller.
+//
+// Harware sketch:
+// LED (20mA, green or red)
+// |\ |
+// | \ |
+// -----| \|----
+// | | /| _|_
+// | | / | | |
+// | / | | 100 Ohm
+// | |___|
+// | |
+// | |
+// - -
+// |O| |O|
+// - -
+// Anode Pin Cathode Pin
+//
+// How it works:
+// In the first phase the LED is turned on in it´s normal mode for 50ms.
+// In the second phase the LED is driven with a reversed voltage for 10ms
+// (anode negative, cathode positive). This will charge the internal capacity
+// with reverse potential. Then the anode pin is configured as a high-impedance
+// input pin. It takes some time until the voltage at the anode pin will raise
+// above the Schmitt-trigger level. This time is depending on the over all
+// circuit resistance, but also very depending on the ambient light.
+//
+// Warning:
+// The capacity of the LED is very low (5..35pF). Do not place the board
+// to a conductive ground. Even humidity will change the blink frequency.
+// Do not touch the components.
+//-----------------------------------------------------------------------------
+
+#include "mbed.h"
+//-----------------------------------------------------------------------------
+
+DigitalInOut anode_pin(PC_10);
+DigitalOut cathode_pin(PC_11);
+//-----------------------------------------------------------------------------
+
+int main(void)
+{
+ anode_pin.output();
+
+ while (1)
+ {
+ // Set normal LED operation, turn on LED for 50ms
+ // Setup PC10 as output
+ anode_pin.output();
+
+ // Turn on LED for 50ms
+ // Set anode (PC10) high and cathode (PC11) low
+ anode_pin = 1;
+ cathode_pin = 0;
+ wait(0.05f);
+
+ // Apply reverse voltage to the LED for reverse charging the LED´s capacity
+ // Set anode (PC10) low and cathode (PC11) high
+ anode_pin = 0;
+ cathode_pin = 1;
+ wait(0.01f);
+
+ // Setup anode (PC10) as input
+ anode_pin.input();
+
+ // Wait until the input voltage raises above the Schmitt trigger level
+ // This time is strongly ambient light depending
+ while (anode_pin.read() == 0)
+ {
+ }
+ }
+}