Demo program for the Oled display
Diff: main.cpp
- Revision:
- 2:1eac3ea8c6e8
- Parent:
- 1:793dbd6d6498
- Child:
- 3:1fb597da3fdf
--- a/main.cpp Fri Jan 09 00:11:48 2015 +0000 +++ b/main.cpp Fri Jan 09 18:21:01 2015 +0000 @@ -3,7 +3,7 @@ OLED32028P1T oled(PTE0,PTE1,PTA12); // Oled Display tx, rx, rs -InterruptIn SignalIn(PTC1); // conection of output NON-inverting DCF module +InterruptIn dcfSignalIn(PTC0); // conection of output NON-inverting DCF module DigitalOut SignalLED(LED3); // indicates DCF signal on Mbed Timer T1,T2,T3; @@ -119,7 +119,9 @@ oled.locate (4,6); oled.printf("drawText time %3.2f mS",T1.read()*1000);T1.reset(); oled.locate (4,11); - oled.printf("printf time %3.2f mS",T2.read()*1000);T2.reset(); + oled.printf("printf time %3.2f mS",T2.read()*1000);T2.reset(); + oled.locate (4,12); + oled.printf("%d",seconds); } T3.reset(); while(1){ @@ -139,23 +141,27 @@ oled.drawTextButton(1, 200, 210,(oled.toRGB(0,100,100)),(FONT12X16),(oled.toRGB(255,255,255)), 1, 1, "DCF Clock"); oled.drawTextButton(1, 252, 185,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "Set RTC"); oled.setTextBackgroundType (TEXT_OPAQUE); - oled.drawText(0,0,(FONT12X16),"RTC Clock",oled.toRGB(255,0,0)); - oled.enableTouch();oled.resetTouchArea(); + oled.drawText(0,0,(FONT12X16),"RTC Clock",oled.toRGB(0,255,0)); + oled.drawText(38,7,(FONT5X7),"Touch position",oled.toRGB(255,0,0)); + oled.enableTouch();oled.resetTouchArea(); + T1.start(); while(IRQ==0){ oled.setFontSize(FONT12X16);oled.locate(0,1); oled.setFontColor(oled.toRGB(255,255,255)); time_t seconds = time(NULL); - strftime(timebuf, 32, "%I:%M:%S %p", localtime(&seconds)); + strftime(timebuf, 32, "%I:%M:%S.", localtime(&seconds)); strftime(datebuf, 32, "%a %d %b %Y ", localtime(&seconds)); - oled.drawText(11,0,(FONT12X16),timebuf,oled.toRGB(255,255,0)); - oled.drawText(11,1,(FONT12X16),datebuf,oled.toRGB(255,255,0)); - - if (seconds != nextsec) {RTCclockupdate();nextsec=seconds;} - oled.getTouch(&xbuffer,&ybuffer); + oled.drawText(11,0,(FONT12X16),timebuf,oled.toRGB(255,255,255)); + oled.drawText(11,1,(FONT12X16),datebuf,oled.toRGB(255,255,255)); + + if (seconds != nextsec){T1.reset();RTCclockupdate();nextsec=seconds;} + oled.locate(20,0); + oled.printf("%02.f ",T1.read()*100); + oled.getTouch(&xbuffer,&ybuffer); - oled.setFontSize(FONT5X7);oled.locate(40,6); // this shows touch position - oled.printf("X %03d Y %03d ",xbuffer,ybuffer); // and can be removed + oled.setFontSize(FONT5X7);oled.locate(40,9); // this indicates touch position + oled.printf("X %03d Y %03d ",xbuffer,ybuffer); // can be removed if((xbuffer>195 && xbuffer<300) && (ybuffer>205 && ybuffer<220)){DCFclock();} if((xbuffer>240 && xbuffer<300) && (ybuffer>182 && ybuffer<200)){RTCsetclock();} @@ -212,8 +218,7 @@ oled.drawTextButton(1, 52, 115,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "+"); oled.drawTextButton(1, 52, 140,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "-"); oled.drawTextButton(1, 88, 115,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "+"); - oled.drawTextButton(1, 88, 140,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "-"); - + oled.drawTextButton(1, 88, 140,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "-"); oled.drawTextButton(1, 174, 115,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "+"); oled.drawTextButton(1, 174, 140,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, "-"); oled.drawTextButton(1, 208, 115,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, " + "); @@ -221,23 +226,38 @@ oled.drawTextButton(1, 270, 115,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, " + "); oled.drawTextButton(1, 270, 140,(oled.toRGB(0,100,100)),(FONT8X12),(oled.toRGB(255,255,255)), 1, 1, " - "); oled.setTextBackgroundType (TEXT_OPAQUE); + oled.setFontSize(FONT8X12);oled.locate (6,14); + oled.setFontColor(oled.toRGB(255,255,255)); + time_t seconds = time(NULL); + oled.printf("time_t = %d seconds",seconds); RTCread(); second=RTCsecond;minute=RTCminute;hour=RTChour;dayofweek=RTCdayofweek;dayofmonth=RTCdayofmonth;month=RTCmonth;year=RTCyear; - while(IRQ==0){ - + while(IRQ==0){ oled.enableTouch(); time_t seconds = time(NULL); - strftime(timebuf, 32, "%H:%M:%S", localtime(&seconds)); - strftime(datebuf, 32, "%a %d %b' %Y", localtime(&seconds)); - oled.drawText(0,2,(FONT12X16),timebuf,oled.toRGB(255,255,255)); - oled.drawText(10,2,(FONT12X16),datebuf,oled.toRGB(255,255,255)); + strftime(timebuf, 26, "%H:%M:%S", localtime(&seconds)); + strftime(datebuf, 26, "%a %d %b' %Y", localtime(&seconds)); + oled.drawText(1,2,(FONT12X16),timebuf,oled.toRGB(255,255,0)); + oled.drawText(10,2,(FONT12X16),datebuf,oled.toRGB(255,255,0)); + oled.setFontSize(FONT8X12);oled.locate (6,5); + oled.setFontColor(oled.toRGB(255,255,255)); + oled.printf("time_t = %d seconds",seconds); oled.getTouch(&xbuffer,&ybuffer); - if((xbuffer>240 && xbuffer<290) && (ybuffer>190 && ybuffer<210)){RTCclock();} - if((xbuffer>20 && xbuffer<109) && (ybuffer>190 && ybuffer<210)){set_time(1396310400);} - if((xbuffer>120 && xbuffer<195) && (ybuffer>195 && ybuffer<210)){RTCset();RTCread(); + if((xbuffer>240 && xbuffer<290) && (ybuffer>190 && ybuffer<210)){IRQ=1;} + if((xbuffer>20 && xbuffer<109) && (ybuffer>190 && ybuffer<210)){ + set_time(1420070400);time_t seconds = time(NULL);RTCread(); second=RTCsecond;minute=RTCminute;hour=RTChour;dayofweek=RTCdayofweek;dayofmonth=RTCdayofmonth;month=RTCmonth;year=RTCyear; + oled.setFontSize(FONT8X12);oled.locate (6,14); + oled.setFontColor(oled.toRGB(255,255,255)); + oled.printf("time_t = %d seconds",seconds); + } + if((xbuffer>120 && xbuffer<195) && (ybuffer>195 && ybuffer<210)){RTCset();time_t seconds = time(NULL);RTCread(); + second=RTCsecond;minute=RTCminute;hour=RTChour;dayofweek=RTCdayofweek;dayofmonth=RTCdayofmonth;month=RTCmonth;year=RTCyear; + oled.setFontSize(FONT8X12);oled.locate (6,14); + oled.setFontColor(oled.toRGB(255,255,255)); + oled.printf("time_t = %d seconds",seconds); } if((xbuffer>25 && xbuffer<40) && (ybuffer>124 && ybuffer<140)){hour++;} @@ -271,9 +291,9 @@ oled.setFontSize(FONT12X16);oled.locate(1,6); - oled.setFontColor(oled.toRGB(60,255,255)); + oled.setFontColor(oled.toRGB(128,255,255)); oled.printf("%2d:%02d:%02d ",hour,minute,second); - oled.printf("%s %02d %s' 20%02d",weekDayName[dayofweek],dayofmonth,monthName[month-1],year); + oled.printf("%s %02d %s' 20%02d",weekDayName[dayofweek],dayofmonth,monthName[month-1],year); } } @@ -343,6 +363,22 @@ void DCFclock() { + oled.clear(); + oled.drawText(0,1,(FONT12X16),("--- DCF77 Atomic Clock ---"),oled.toRGB(255,255,255)); + oled.drawText(3,3,(FONT12X16),("Checking Signal..."),oled.toRGB(255,255,255)); + T1.reset();T1.start(); + while(dcfSignalIn == 1 && T1.read()<.5){} + while(dcfSignalIn == 0 && T1.read()<.5){} + T1.stop(); + if (T1.read()>.5){ + T1.stop(); + oled.drawText(0,5,(FONT12X16),(" !! No signal detected !! "),oled.toRGB(255,0,0)); + oled.drawText(2,9,(FONT8X12),("Connect Non inverting signal of DCF"),oled.toRGB(255,255,255)); + oled.drawText(2,10,(FONT8X12),("receiver module to specified Pin."),oled.toRGB(255,255,255)); + oled.drawText(5,12,(FONT8X12),("Running Demo mode."),oled.toRGB(255,255,255)); + wait(5); + } + wait(1); oled.clear();DCFbitmapdraw();RTCread(); second=RTCsecond;minute=RTCminute;hour=RTChour;dayofweek=RTCdayofweek;dayofmonth=RTCdayofmonth;month=RTCmonth;year=RTCyear; if(tz==0) {oled.drawText(0,0,(FONT8X12)," RTC Clock Time (GMT)",oled.toRGB(255,0,0));} @@ -361,8 +397,20 @@ oled.drawLine(288,190,305,190, oled.toRGB(225, 255, 255)); oled.drawText(0,26,(FONT5X7)," 0 start min hour Dt dy mon year 60",oled.toRGB(255,0,0)); oled.setTouchArea(240,140,290,160); - start=0;sync=0;x=0;y=5;r=0;SignalStatus=0;laststart=2;loop=0;interrupt_counter = 0;dcf_sec=0;error_count=0; + start=0;sync=1;x=0;y=5;r=0;SignalStatus=0; + laststart=2; + loop=0; + //RTCset=0; + interrupt_counter = 0;dcf_sec=0;error_count=0,display=0;signal_error=0;rtcset_times=0; + hour = 0;minute = 0,second = 0,dayofweek = 6;dayofmonth = 1;month = 1;year = 0; + T1.start(); + while(dcfSignalIn == 1 && T1.read()<.5){} + while(dcfSignalIn == 0 && T1.read()<.5){} + T1.stop(); + dcfSignalIn.rise(dcfIRQ); //Trigger dcfISR Ticker on rising edge of DCF pulse + interrupt_counter = 0;sync=0; + Ticker50ms.attach(& dcfISR, .05); while (IRQ==0) { @@ -437,7 +485,7 @@ if (interrupt_counter == 11 & second == 1) { oled.setFontSize(FONT5X7);oled.locate(34,5); oled.setFontColor(oled.toRGB(255,255,255)); - oled.printf("RTC set x %d", rtcset_times); + oled.printf("RTC set x %d", rtcset_times); } if (interrupt_counter == 12){ @@ -454,8 +502,8 @@ } if (interrupt_counter==13){ - if (start==0 && laststart != start) {oled.drawText(26,18,(FONT5X7),("No Sync"),oled.toRGB(255,0,0));laststart=start;} - if (start==1 && laststart != start) {oled.drawText(26,18,(FONT5X7),("In Sync"),oled.toRGB(0,255,0));laststart=start;} + if (start==0 && laststart != start) {oled.drawText(26,18,(FONT5X7),("No Sync "),oled.toRGB(255,0,0));laststart=start;} + if (start==1 && laststart != start) {oled.drawText(26,18,(FONT5X7),("In Sync - running"),oled.toRGB(0,255,0));laststart=start;} } if (interrupt_counter>13){ @@ -465,7 +513,7 @@ oled.displayControl(0x01,0x01);display=1; oled.resetTouchArea();}} if((xbuffer>240 && xbuffer<290) && (ybuffer>140 && ybuffer<160)){ - SignalIn.rise(NULL);Ticker50ms.detach();IRQ=1;} + dcfSignalIn.rise(NULL);Ticker50ms.detach();IRQ=1;} } if (interrupt_counter == 19){DCFbitstatus();} @@ -495,6 +543,7 @@ month=p_month; year=p_year; oled.drawText(36,7,(FONT8X12),"*",oled.toRGB(0,255,0)); + rtcset_times++; } void DCFbitprint() { @@ -616,7 +665,7 @@ { interrupt_counter++;loop=0; - SignalLED = SignalIn; // Show dcfSignal state on LED + SignalLED = !dcfSignalIn; // Show dcfSignal state on LED if (interrupt_counter == 20) { // 50mS x 20 = 1000mS = 1 Second interrupt_counter = 0;second++;dcf_sec++; @@ -637,28 +686,28 @@ switch (interrupt_counter) { case 1: { // 50mS after start of second pulse - dcf_status.DCFsample50 = (SignalIn); + dcf_status.DCFsample50 = (dcfSignalIn); break;} case 3: { // 150mS after start of second pulse (bit "1" dcf Data) - dcf_status.DCFsample150 = (SignalIn); + dcf_status.DCFsample150 = (dcfSignalIn); break;} case 6: { // 300mS after start of second (signal error if true) - dcf_status.DCFsample300 = (SignalIn); - if (SignalIn) {dcf_error = 1;} + dcf_status.DCFsample300 = (dcfSignalIn); + if (dcfSignalIn) {dcf_error = 1;} break;} case 10: { // 500mS after start of second (signal error if true) - dcf_status.DCFsample500 = (SignalIn); - if (SignalIn) {dcf_error = 1;} + dcf_status.DCFsample500 = (dcfSignalIn); + if (dcfSignalIn) {dcf_error = 1;} break;} case 12: { // 600mS after start of second (signal error if true) - dcf_status.DCFsample600 = (SignalIn); - if (SignalIn) {dcf_error = 1;} + dcf_status.DCFsample600 = (dcfSignalIn); + if (dcfSignalIn) {dcf_error = 1;} break;} } if (dcf_status.DCFsample50==0 && dcf_sec<58){sync=0;} if (interrupt_counter==1){ - if (SignalIn){nosignal=1;} + if (dcfSignalIn){nosignal=1;} else nosignal++; if (nosignal>5){nosignal=2; SignalStatus = 5;signal_error=1;} }