ZI6 lib

Dependencies:   C12832

Dependents:   PURS_ZI_006

Files at this revision

API Documentation at this revision

Comitter:
tbjazic
Date:
Thu Jun 23 13:45:33 2016 +0000
Commit message:
initial

Changed in this revision

C12832.lib Show annotated file Show diff for this revision Revisions of this file
SinusGen.cpp Show annotated file Show diff for this revision Revisions of this file
SinusGen.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 3dddb6a52298 C12832.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/C12832.lib	Thu Jun 23 13:45:33 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/askksa12543/code/C12832/#990d5eec2ef6
diff -r 000000000000 -r 3dddb6a52298 SinusGen.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SinusGen.cpp	Thu Jun 23 13:45:33 2016 +0000
@@ -0,0 +1,44 @@
+#include "mbed.h"
+#include "C12832.h"
+#include "SinusGen.h"
+
+SinusGen::SinusGen(PinName pot1Pin, PinName pot2Pin, PinName tipkaloPin) : pot1(pot1Pin), pot2(pot2Pin), tipkalo(tipkaloPin), lcd(p5, p7, p6, p8, p11), led1(LED1), led2(LED2), led3(LED3), led4(LED4) {
+    ticker.attach(this, &SinusGen::generirajPrikazi, 0.05);
+    tipkalo.rise(this, &SinusGen::izborLedice);
+    lcd.cls();
+    izbor = 0;
+    t = 0;
+    led1 = led2 = led3 = led4 = 0;
+    debounce.start();
+}
+
+void SinusGen::generirajPrikazi() {
+    U = pot1.read();
+    A = pot2.read();
+    t += 0.05;
+    y = U + A*sin(3.14f*t);
+    lcd.locate(0,3);
+    lcd.printf("y(t) = %.2f + %.2fsin(3.14t)", U, A);
+    led1 = led2 = led3 = led4 = 0;
+    switch(izbor) {
+        case 0:
+            led1 = y;
+            break;
+        case 1:
+            led2 = y;
+            break;
+        case 2:
+            led3 = y;
+            break;
+        case 3:
+            led4 = y;
+            break;
+    }
+}
+
+void SinusGen::izborLedice() {
+    if (debounce.read_ms() > 20) {
+        izbor = ++izbor % 4;
+        debounce.reset();
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 3dddb6a52298 SinusGen.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SinusGen.h	Thu Jun 23 13:45:33 2016 +0000
@@ -0,0 +1,24 @@
+#ifndef SINUS_GEN
+#define SINUS_GEN
+
+#include "mbed.h"
+#include "C12832.h"
+
+class SinusGen {
+    public:
+    SinusGen(PinName temp1Pin, PinName temp2Pin, PinName tipkaloPin);
+    
+    private:
+    AnalogIn pot1, pot2;
+    InterruptIn tipkalo;
+    C12832 lcd;
+    PwmOut led1, led2, led3, led4;
+    Ticker ticker;
+    void generirajPrikazi();
+    int izbor;
+    float U, A, y, t;
+    void izborLedice();
+    Timer debounce;
+};
+
+#endif
\ No newline at end of file