Pametna_kuca

Dependencies:   pcinput TextLCD

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