#include <mechButton.h>
const int A_BTN_PIN = 10;
const int B_BTN_PIN = 9;
const int C_BTN_PIN = 8;
const int D_BTN_PIN = 7;
mechButton aBtn(A_BTN_PIN);
mechButton bBtn(B_BTN_PIN);
mechButton cBtn(C_BTN_PIN);
mechButton dBtn(D_BTN_PIN);
char* makeMsg(int value) {
static char msgPrice[8];
int dollarVal = value / 100;
int centVal = value % 100;
sprintf(msgPrice, "$%d.%02d", dollarVal, centVal); // add null????????
char* msgPointer = msgPrice;
return msgPointer;
}
void aCallback(void) {
if (!aBtn.trueFalse()) {
Serial.println("A pressed");
char* printVal = makeMsg(175);
Serial.print(printVal);
Serial.println();
}
}
void bCallback(void) {
if (!bBtn.trueFalse()) {
Serial.println("B pressed");
char* printVal = makeMsg(495);
Serial.print(printVal);
Serial.println();
}
}
void cCallback(void) {
if (!cBtn.trueFalse()) {
Serial.println("C pressed");
char* printVal = makeMsg(365);
Serial.print(printVal);
Serial.println();
char* printVal2 = makeMsg(635);
Serial.print(printVal2);
Serial.println();
}
}
void dCallback(void) {
//char msgPrice[8];
char msgCredit[8];
int credit = 775;
int price = 885;
if (!dBtn.trueFalse()) {
int cdollarVal = credit / 100;
int ccentVal = credit % 100;
sprintf(msgCredit, "$%d.%02d", cdollarVal, ccentVal);
//int dollarVal = price / 100;
//int centVal = price % 100;
//sprintf(msgPrice, "$%d.%02d", dollarVal, centVal);
char* printVal = makeMsg(price);
Serial.println("D pressed");
Serial.print(msgCredit);
Serial.println();
Serial.print(printVal);
Serial.println();
}
}
void setup() {
Serial.begin(115200);
pinMode(A_BTN_PIN, INPUT_PULLUP);
pinMode(B_BTN_PIN, INPUT_PULLUP);
pinMode(C_BTN_PIN, INPUT_PULLUP);
pinMode(D_BTN_PIN, INPUT_PULLUP);
aBtn.setCallback(aCallback);
bBtn.setCallback(bCallback);
cBtn.setCallback(cCallback);
dBtn.setCallback(dCallback);
}
void loop() {
idle();
}