US, Vjezba 3 Stol 8, Amer Surkovic, Mirza Music Zadatak 1

Dependencies:   N5110 mbed

Committer:
2016US_AmerSurkovic
Date:
Fri Mar 18 14:50:40 2016 +0000
Revision:
0:af71cde4bf71
US, Vjezba 3 Stol 8, Amer Surkovic, Mirza Music Zadatak 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
2016US_AmerSurkovic 0:af71cde4bf71 1 #include "mbed.h"
2016US_AmerSurkovic 0:af71cde4bf71 2 #include "N5110.h"
2016US_AmerSurkovic 0:af71cde4bf71 3 #include "string.h"
2016US_AmerSurkovic 0:af71cde4bf71 4
2016US_AmerSurkovic 0:af71cde4bf71 5 #define dp23 P0_0
2016US_AmerSurkovic 0:af71cde4bf71 6
2016US_AmerSurkovic 0:af71cde4bf71 7 // N5110lcd (VCC, SCE, RST, DC, MOSI, SCLK, LED)) ;
2016US_AmerSurkovic 0:af71cde4bf71 8 N5110 lcd (dp4, dp24, dp23, dp25, dp2, dp6, dp18);
2016US_AmerSurkovic 0:af71cde4bf71 9 DigitalOut enable (dp14);
2016US_AmerSurkovic 0:af71cde4bf71 10
2016US_AmerSurkovic 0:af71cde4bf71 11 // Program mjeri trenutni otpor potenciometra izmedju
2016US_AmerSurkovic 0:af71cde4bf71 12 // tacaka dp9 i GND
2016US_AmerSurkovic 0:af71cde4bf71 13
2016US_AmerSurkovic 0:af71cde4bf71 14 DigitalIn taster(dp1);
2016US_AmerSurkovic 0:af71cde4bf71 15
2016US_AmerSurkovic 0:af71cde4bf71 16 AnalogIn voltMetar_napon(dp9);
2016US_AmerSurkovic 0:af71cde4bf71 17
2016US_AmerSurkovic 0:af71cde4bf71 18 int main() {
2016US_AmerSurkovic 0:af71cde4bf71 19 // Analogni napon 0-3.3V sa analognog ulaza se
2016US_AmerSurkovic 0:af71cde4bf71 20 // preslikava u float vrijednosti 0.0-1.0
2016US_AmerSurkovic 0:af71cde4bf71 21 float otpor = 0;
2016US_AmerSurkovic 0:af71cde4bf71 22
2016US_AmerSurkovic 0:af71cde4bf71 23 //deaktivacija led dioda
2016US_AmerSurkovic 0:af71cde4bf71 24 enable=1;
2016US_AmerSurkovic 0:af71cde4bf71 25
2016US_AmerSurkovic 0:af71cde4bf71 26 //inicijalizacija displeja
2016US_AmerSurkovic 0:af71cde4bf71 27 lcd.init();
2016US_AmerSurkovic 0:af71cde4bf71 28 // ("String", koordinata X, koordinata Y)
2016US_AmerSurkovic 0:af71cde4bf71 29
2016US_AmerSurkovic 0:af71cde4bf71 30 int brojac = 0;
2016US_AmerSurkovic 0:af71cde4bf71 31
2016US_AmerSurkovic 0:af71cde4bf71 32 while(1) {
2016US_AmerSurkovic 0:af71cde4bf71 33 // R = U*I
2016US_AmerSurkovic 0:af71cde4bf71 34 if(taster==1){
2016US_AmerSurkovic 0:af71cde4bf71 35 brojac++;
2016US_AmerSurkovic 0:af71cde4bf71 36 if(brojac>1) brojac=0;
2016US_AmerSurkovic 0:af71cde4bf71 37 }
2016US_AmerSurkovic 0:af71cde4bf71 38
2016US_AmerSurkovic 0:af71cde4bf71 39 otpor = voltMetar_napon.read() * 10000;
2016US_AmerSurkovic 0:af71cde4bf71 40
2016US_AmerSurkovic 0:af71cde4bf71 41 if(brojac==0){
2016US_AmerSurkovic 0:af71cde4bf71 42 // lcd.clear();
2016US_AmerSurkovic 0:af71cde4bf71 43 lcd.printString("Napon: ", 0, 0);
2016US_AmerSurkovic 0:af71cde4bf71 44 char ispis_napona[6];
2016US_AmerSurkovic 0:af71cde4bf71 45 // Format punjenja: (buffer, format, podaci)
2016US_AmerSurkovic 0:af71cde4bf71 46 sprintf(ispis_napona, "%.2f", (float)voltMetar_napon*3.3);
2016US_AmerSurkovic 0:af71cde4bf71 47 ispis_napona[5]='\0';
2016US_AmerSurkovic 0:af71cde4bf71 48 // Ispis na LCD
2016US_AmerSurkovic 0:af71cde4bf71 49 lcd.printString(ispis_napona, 50, 0);
2016US_AmerSurkovic 0:af71cde4bf71 50 }
2016US_AmerSurkovic 0:af71cde4bf71 51 else if(brojac==1){
2016US_AmerSurkovic 0:af71cde4bf71 52 // lcd.clear();
2016US_AmerSurkovic 0:af71cde4bf71 53 lcd.printString("Otpor: ", 0, 0);
2016US_AmerSurkovic 0:af71cde4bf71 54 char ispis_otpora[6];
2016US_AmerSurkovic 0:af71cde4bf71 55 sprintf(ispis_otpora, "%.2f", otpor);
2016US_AmerSurkovic 0:af71cde4bf71 56 ispis_otpora[5]='\0';
2016US_AmerSurkovic 0:af71cde4bf71 57 lcd.printString(ispis_otpora, 50, 0);
2016US_AmerSurkovic 0:af71cde4bf71 58 }
2016US_AmerSurkovic 0:af71cde4bf71 59
2016US_AmerSurkovic 0:af71cde4bf71 60 wait(0.5);
2016US_AmerSurkovic 0:af71cde4bf71 61 }
2016US_AmerSurkovic 0:af71cde4bf71 62 }