Dependencies:   pcinput TextLCD

Committer:
ijajcevic
Date:
Mon Mar 01 19:21:54 2021 +0000
Revision:
1:9e5c378547dc
Parent:
0:8c4ff7ea7eb9
Child:
2:4379fe6ea43b
Projekt Pametna kuca

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ijajcevic 0:8c4ff7ea7eb9 1 /* mikrupravljači
ijajcevic 0:8c4ff7ea7eb9 2 * projektni zadatak
ijajcevic 0:8c4ff7ea7eb9 3 */
ijajcevic 0:8c4ff7ea7eb9 4
ijajcevic 0:8c4ff7ea7eb9 5 #include "mbed.h"
ijajcevic 0:8c4ff7ea7eb9 6 #include "TextLCD.h"
ijajcevic 0:8c4ff7ea7eb9 7 #include "pcinput.h"
ijajcevic 0:8c4ff7ea7eb9 8
ijajcevic 0:8c4ff7ea7eb9 9 PwmOut PWM1(PC_8);
ijajcevic 0:8c4ff7ea7eb9 10 Timer debounce;
ijajcevic 0:8c4ff7ea7eb9 11 InterruptIn gumb(PC_10);
ijajcevic 0:8c4ff7ea7eb9 12 DigitalOut ledica2(PC_9);
ijajcevic 0:8c4ff7ea7eb9 13 Serial bt(PA_9, PA_10); // TX, RX za bluetooth
ijajcevic 0:8c4ff7ea7eb9 14 void toggle(void);
ijajcevic 0:8c4ff7ea7eb9 15 void ventila(void);
ijajcevic 0:8c4ff7ea7eb9 16 void ledic(void);
ijajcevic 0:8c4ff7ea7eb9 17 TextLCD lcd(PA_0,PA_1,PA_4,PB_0,PC_1,PC_0); //rs, e, d0, d1, d2, d3
ijajcevic 0:8c4ff7ea7eb9 18 Ticker flipper1;
ijajcevic 0:8c4ff7ea7eb9 19 DigitalOut ledica1(PB_8);
ijajcevic 0:8c4ff7ea7eb9 20 DigitalOut zarulja1(PC_2);
ijajcevic 0:8c4ff7ea7eb9 21 DigitalOut zarulja2(PC_3);
ijajcevic 0:8c4ff7ea7eb9 22 void zadatak1(void);
ijajcevic 0:8c4ff7ea7eb9 23 int prva(int k, int x); // inicijalizacija funkcije prva
ijajcevic 0:8c4ff7ea7eb9 24 int druga(int l, int x); // inicijalizacija funkcije druga
ijajcevic 0:8c4ff7ea7eb9 25
ijajcevic 0:8c4ff7ea7eb9 26
ijajcevic 0:8c4ff7ea7eb9 27 int main()
ijajcevic 0:8c4ff7ea7eb9 28 {
ijajcevic 0:8c4ff7ea7eb9 29 // inicijalizacija
ijajcevic 0:8c4ff7ea7eb9 30 debounce.start();
ijajcevic 0:8c4ff7ea7eb9 31 gumb.rise(&toggle);
ijajcevic 0:8c4ff7ea7eb9 32 bt.baud(9600);
ijajcevic 0:8c4ff7ea7eb9 33 inicijalizacija(); // ispis prvog reda na LCD
ijajcevic 0:8c4ff7ea7eb9 34 float f;
ijajcevic 0:8c4ff7ea7eb9 35 int i=1;
ijajcevic 0:8c4ff7ea7eb9 36 int k=1;
ijajcevic 0:8c4ff7ea7eb9 37 int l=1;
ijajcevic 0:8c4ff7ea7eb9 38
ijajcevic 0:8c4ff7ea7eb9 39 gumb.mode(PullUp);
ijajcevic 0:8c4ff7ea7eb9 40 PWM1.period(0.01);
ijajcevic 0:8c4ff7ea7eb9 41 PWM1=0.25;
ijajcevic 0:8c4ff7ea7eb9 42 f=0.5;
ijajcevic 0:8c4ff7ea7eb9 43 lcd.locate(0,0);
ijajcevic 0:8c4ff7ea7eb9 44 lcd.printf("Vrijednost pwm:");
ijajcevic 0:8c4ff7ea7eb9 45 flipper1.attach(&flip1, 0.2);
ijajcevic 0:8c4ff7ea7eb9 46
ijajcevic 0:8c4ff7ea7eb9 47 while (1) {
ijajcevic 0:8c4ff7ea7eb9 48 char c;
ijajcevic 0:8c4ff7ea7eb9 49 if (pc.readable()){
ijajcevic 0:8c4ff7ea7eb9 50 c = KeyInput(); //vuče iz pcinput.cpp
ijajcevic 0:8c4ff7ea7eb9 51 pc.printf("Vrijednost PWM-a: %f\n\r",1-f);
ijajcevic 0:8c4ff7ea7eb9 52 i=c;
ijajcevic 0:8c4ff7ea7eb9 53 }
ijajcevic 0:8c4ff7ea7eb9 54 f=((i-48)/10.0);
ijajcevic 0:8c4ff7ea7eb9 55 PWM1=f;
ijajcevic 0:8c4ff7ea7eb9 56
ijajcevic 0:8c4ff7ea7eb9 57
ijajcevic 0:8c4ff7ea7eb9 58 lcd.locate(0,1);
ijajcevic 0:8c4ff7ea7eb9 59 lcd.printf("%.2f ", f);
ijajcevic 0:8c4ff7ea7eb9 60 if (bt.readable()) {
ijajcevic 0:8c4ff7ea7eb9 61 char x = bt.getc();
ijajcevic 0:8c4ff7ea7eb9 62 pc.printf("Bluetooth citljiv %i\n\r", bt.readable());
ijajcevic 0:8c4ff7ea7eb9 63 k=prva(k,x);
ijajcevic 0:8c4ff7ea7eb9 64 l=druga(l,x);
ijajcevic 0:8c4ff7ea7eb9 65 }
ijajcevic 0:8c4ff7ea7eb9 66
ijajcevic 0:8c4ff7ea7eb9 67 }
ijajcevic 0:8c4ff7ea7eb9 68 }
ijajcevic 0:8c4ff7ea7eb9 69
ijajcevic 0:8c4ff7ea7eb9 70 void toggle() //za deboune i mijenjanje stanja bitnog trošila
ijajcevic 0:8c4ff7ea7eb9 71 {
ijajcevic 0:8c4ff7ea7eb9 72 if (debounce.read_ms()>= 150)
ijajcevic 0:8c4ff7ea7eb9 73 ledica2=!ledica2;
ijajcevic 0:8c4ff7ea7eb9 74 debounce.reset();
ijajcevic 0:8c4ff7ea7eb9 75 }
ijajcevic 0:8c4ff7ea7eb9 76
ijajcevic 0:8c4ff7ea7eb9 77 int prva(int k, int x) // funkcija 'prva' za bt
ijajcevic 0:8c4ff7ea7eb9 78 {
ijajcevic 0:8c4ff7ea7eb9 79 if ( x == 'a') {
ijajcevic 0:8c4ff7ea7eb9 80 k +=1;
ijajcevic 0:8c4ff7ea7eb9 81 }
ijajcevic 0:8c4ff7ea7eb9 82 pc.printf("Prva zarulja %i\n\r",k);
ijajcevic 0:8c4ff7ea7eb9 83 if (k % 2 == 0 && k != 0) {
ijajcevic 0:8c4ff7ea7eb9 84
ijajcevic 0:8c4ff7ea7eb9 85 zarulja1 = 1;
ijajcevic 0:8c4ff7ea7eb9 86 bt.printf("Upaljena zarulja\n");
ijajcevic 0:8c4ff7ea7eb9 87 bt.printf("led1 ON\n");
ijajcevic 0:8c4ff7ea7eb9 88
ijajcevic 0:8c4ff7ea7eb9 89 }
ijajcevic 0:8c4ff7ea7eb9 90 if (k % 2 == 1 && k != 1) {
ijajcevic 0:8c4ff7ea7eb9 91 zarulja1 = 0;
ijajcevic 0:8c4ff7ea7eb9 92 bt.printf("Ugasena zarulja\n");
ijajcevic 0:8c4ff7ea7eb9 93 bt.printf("led1 OFF\n");
ijajcevic 0:8c4ff7ea7eb9 94 k=1;
ijajcevic 0:8c4ff7ea7eb9 95 }
ijajcevic 0:8c4ff7ea7eb9 96 return k;
ijajcevic 0:8c4ff7ea7eb9 97 }
ijajcevic 0:8c4ff7ea7eb9 98
ijajcevic 0:8c4ff7ea7eb9 99 int druga(int l, int x) // funkcija 'druga'
ijajcevic 0:8c4ff7ea7eb9 100 {
ijajcevic 0:8c4ff7ea7eb9 101 if ( x == 'b') {
ijajcevic 0:8c4ff7ea7eb9 102 l +=1;
ijajcevic 0:8c4ff7ea7eb9 103 }
ijajcevic 0:8c4ff7ea7eb9 104 pc.printf("Druga zarulja %i\n\r",l);
ijajcevic 0:8c4ff7ea7eb9 105 if (l % 2 == 0 && l != 0) {
ijajcevic 0:8c4ff7ea7eb9 106
ijajcevic 0:8c4ff7ea7eb9 107 zarulja2 = 1;
ijajcevic 0:8c4ff7ea7eb9 108 bt.printf("Upaljena zarulja 2\n");
ijajcevic 0:8c4ff7ea7eb9 109 bt.printf("led2 ON\n");
ijajcevic 0:8c4ff7ea7eb9 110 pc.printf("led2 ON\n");
ijajcevic 0:8c4ff7ea7eb9 111
ijajcevic 0:8c4ff7ea7eb9 112 }
ijajcevic 0:8c4ff7ea7eb9 113 if (l % 2 == 1 && l !=1 ) {
ijajcevic 0:8c4ff7ea7eb9 114 zarulja2 = 0;
ijajcevic 0:8c4ff7ea7eb9 115 bt.printf("Ugasena zarulja 2\n");
ijajcevic 0:8c4ff7ea7eb9 116 bt.printf("led2 OFF\n");
ijajcevic 0:8c4ff7ea7eb9 117 l=1;
ijajcevic 0:8c4ff7ea7eb9 118 }
ijajcevic 0:8c4ff7ea7eb9 119 return l;
ijajcevic 0:8c4ff7ea7eb9 120 }