Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please I need help fixing this code. I\'m trying to design a circuit that will d

ID: 2079366 • Letter: P

Question

Please I need help fixing this code. I'm trying to design a circuit that will display a digital clock on the LCD, and when interrupted (with a push button), it will display temperature measure. And after few seconds, it will the LCD screen will return to displaying digital clock.

#include "mbed.h"
#include "TextLCD.h"
#include "TMP102.h"

I2C temp(p9, p10); //A0 pin is connected to ground
InterruptIn event(p21);
TextLCD lcd(p15, p16, p17, p18, p19, p20);

int hours, minutes, seconds;

void trigger(){
    lcd.printf("triggered! ");
    }

int main()
    {
        event.rise(&trigger);
while(1) {
    wait(5);
    lcd.cls();
    lcd.locate(0,1);
   
    if(seconds==60){
        seconds=0;
        minutes++;
    }
        if(minutes==60){
        minutes=0;
        hours++;
    }
        if(hours==24){
        hours=0;
    }
    lcd.printf("%02d:%02d:%02d", hours, minutes, seconds);
    wait(5);
    }
}

Please, if you don't know it, DO NOT ANSWER IT. I've had many people answered it with my exact code and I've had to post it all over again.

Thanks.

Explanation / Answer

#include "mbed.h"
#include "TextLCD.h"
#include "TMP102.h"
I2C temp(p9, p10); //A0 pin is connected to ground
InterruptIn event(p21);
TextLCD lcd(p15, p16, p17, p18, p19, p20);
struct timer{
int hr,min,sec;
};
int main()
{
timer a;
a.hr = 0;
a.min = 0;
a.sec = 0;
if (p21==0)
{
for(int i = 0; i<24; i++)
{
if(a.hr == 23)
{
a.hr = 0;
}
for(int j = 0; j<60; j++)
{
if(a.min == 59)
{
a.min = 0;
}
for(int k = 0; k<60; k++)
{
if(a.sec == 59)
{
a.sec = 0;
}
lcd.prinf("%02d:%02d:%02d", hours, minutes, seconds);
  
}   
a.min++;
}
a.hr++;
}
}
else
temp=0;
for (i=0;i<=49;i++) {
temperature = temperature+ I2C temp(p9, p10);
delay_ms(1);
}
temperature=temperature/50; // calculating average from sensor
temperature=temperature*4.57;
lcd.prinf("%d",temperature);
}