Mjerenje napona - 03.11

Dependencies:   mbed

Fork of VT1_Pervan by Applied engineering Team

Revision:
4:01e6c90b206d
Parent:
3:30a434029ace
Child:
5:0406c84a3d6f
--- a/main.cpp	Thu Nov 10 19:02:06 2016 +0000
+++ b/main.cpp	Thu Nov 10 19:48:08 2016 +0000
@@ -1,24 +1,14 @@
-// host terminal LED dimmer control
 #include "mbed.h"
-Serial pc(USBTX, USBRX); // tx, rx
-PwmOut PWM1(p21);
-float brightness=0.0;
+InterruptIn button(p18); // Interrupt on digital pushbutton input p18
+DigitalOut led1(p5); // digital out to p5
+Timer debounce; // define debounce timer
+void toggle(void); // function prototype
 int main() {
-PWM1.period(0.010); // set PWM period to 10 ms
-PWM1=0.8; // set duty cycle to 80%
-pc.printf("Control of LED dimmer by host terminal\n\r");
-pc.printf("Press 'u' = brighter, 'd' = dimmer\n\r");
-while(1) {
-char c = pc.getc();
-wait(0.001);
-if((c == 'u') && (brightness < 1.0)) {
-brightness += 0.1;
-PWM1= brightness;
-}
-if((c == 'd') && (brightness > 0.0)) {
-brightness -= 0.1;
-PWM1= brightness;
-}
-pc.printf("%c %1.3f \n \r",c,brightness);
-}
+debounce.start();
+button.rise(&toggle); // attach the address of the toggle
+} // function to the rising edge
+void toggle() {
+if (debounce.read_ms()>200) // only allow toggle if debounce timer
+led1=!led1; // has passed 200 ms
+debounce.reset(); // restart timer when the toggle is performed
 }
\ No newline at end of file