Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

Select one: a. 2 b. 0 C. 4 d. 6

Answered: 1 week ago

Question

Discuss How do you implement Atomicity and Durability?

Answered: 1 week ago

Question

Discuss about Complex integrity constraints in SQL?

Answered: 1 week ago

Question

Explain about Schema refinement in Database design?

Answered: 1 week ago

Question

Illustrate Concurrent execution of transaction with examples?

Answered: 1 week ago