I need help on Hardware interrup with the mbed. So far, the below syntax is what
ID: 2079353 • Letter: I
Question
I need help on Hardware interrup with the mbed.
So far, the below syntax is what I've got. I need the Temperature to display only when the interrupt button is pressed and once its displayed, will stay for few seconds and return back to showing the clock running. Thanks in advance.
#include "mbed.h"
#include "TextLCD.h"
#include "TMP102.h"
bool isHigh = false;
Timer tempo;
TextLCD lcd(p15, p16, p17, p18, p19, p20);
TMP102 temp(p9, p10, 0x92); //A0 pin is connected to ground
InterruptIn interr(p21);
int hours, minutes, seconds;
void interruptClock();
int main()
{
hours=0;
minutes=0;
seconds=0;
while (true) {
if(seconds==60){
seconds=0;
minutes++;
}
if(minutes==60){
minutes=0;
hours++;
}
if(hours==24){
hours=0;
}
interr.rise(&interruptClock);
wait(1);
float temperature = tempo.read_us();
lcd.cls();
lcd.locate(0,1);
lcd.printf("Temp:%3.1f", temp.read());
lcd.printf("%02d:%02d:%02d", hours, minutes, seconds);
seconds++;
tempo.reset();
wait(1);
}
}
void interruptClock()
{
if (!isHigh)
{
tempo.start();
isHigh = true;
}
else
{
tempo.stop();
interr.rise(NULL);
isHigh = false;
}
}
Explanation / Answer
#include "mbed.h"
#include "TextLCD.h"
#include "TMP102.h"
bool isHigh = false;
Timer tempo;
TextLCD lcd(p15, p16, p17, p18, p19, p20);
TMP102 temp(p9, p10, 0x92); //A0 pin is connected to ground
InterruptIn interr(p21);
int hours, minutes, seconds;
void interruptClock()
{
}
int main()
{
hours=0;
minutes=0;
seconds=0;
}
while (true) {
if(seconds==60){
seconds=0;
minutes++;
}
if(minutes==60){
minutes=0;
hours++;
}
if(hours==24){
hours=0;
}
interr.rise(&interruptClock);
wait(1);
float temperature = tempo.read_us();
lcd.cls();
lcd.locate(0,1);
lcd.printf("Temp:%3.1f", temp.read());
lcd.printf("%02d:%02d:%02d", hours, minutes, seconds);
seconds++;
tempo.reset();
wait(1);
}
}
void interruptClock()
{
if (!isHigh)
{
tempo.start();
isHigh = true;
}
else
{
tempo.stop();
interr.rise(NULL);
isHigh = false;
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.