Question
#include mbed.h #include C12832.h C12832 lcd(D11, D13, D12, D7, D10); class RGBLED { public: RGBLED(PinName red, PinName green, PinName blue) : _red(red), _green(green), _blue(blue) {
#include "mbed.h"
#include "C12832.h"
C12832 lcd(D11, D13, D12, D7, D10);
class RGBLED {
public:
RGBLED(PinName red, PinName green, PinName blue) :
_red(red), _green(green), _blue(blue) {
}
void Yellow() {
_red = 1;
_green = 1;
_blue = 0;
}
void Red() {
_red = 1;
_green = 0;
_blue = 0;
}
void Blue() {
_red = 0;
_green = 0;
_blue = 1;
}
private:
DigitalOut _red;
DigitalOut _green;
DigitalOut _blue;
};
RGBLED led(D5, D9, D8);
InterruptIn btnUp(D6);
InterruptIn btnDown(D7);
InterruptIn btnFire(D8);
Ticker cursorTicker;
int num1 = 1;
int num2 = 1;
char op = '+';
void calculate() {
float result;
if(op == '+') {
result = num1 + num2;
} else if (op == '-') {
result = num1 - num2;
} else if (op == '*') {
result = num1 * num2;
} else if (op == '/') {
result = num1 / (float)num2;
} else if (op == '^') {
result = pow(num1, num2);
}
lcd.locate(0,0);
lcd.write("%d %c %d = %.2f ", num1, op, num2, result);
}
void cursor() {
static bool showCursor = true;
if(showCursor) {
lcd.locate(2, 15);
lcd.write("_");
}
else {
lcd.locate(2, 15);
lcd.write(" ");
}
showCursor = !showCursor;
}
void btnUpPressed() {
if(btnFire.read() == 0) {
num1++;
if(num1 > 9) {
num1 = 0;
}
} else {
num2++;
if(num2 > 9) {
num2 = 0;
}
}
calculate();
}
void btnDownPressed() {
// Similar to btnUpPressed
}
void btnFirePressed() {
static int curNum = 0;
curNum++;
if(curNum > 1) {
curNum = 0;
}
if(curNum == 0) {
// Update num1
} else {
// Update num2
}
// Cycle op
calculate();
}
int main() {
lcd.locate(0,0);
lcd.write("Test");
led.Red();
lcd.locate(0,0);
lcd.write("1 + 1 = 2.00 ");
cursorTicker.attach(&cursor, 0.5);
btnUp.rise(&btnUpPressed);
btnDown.rise(&btnDownPressed);
btnFire.rise(&btnFirePressed);
while(1) {
// empty
}
}
This is my code for program that uses timers and callbacks (ISRs) to implement a functional calculator which can accept two integer inputs. But there is a build fail every time I run it but it is not showing any errors as well.
Would love to know how could I solve this problem.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started