spatula:
Hi, I'm trying to figure out what you want to do and I'm still unsure. The case I have in mind is a sort of simple calculator using postfix notation, so if you type "123+-" this is translated into ((2+3)-1). Your case is probably simpler because you seem to allow only a value followed by an operator, so you never get two consecutive values or two consecutive operators.
Both ways, you need to make a distinction between values and operators: if a value key is entered you have to save the value until an operator key is pressed (you may display the value, but that is not essential and depends on how you design your "user interface"); if an operator key is pressed you need to perform the calculation and display it. You also need to save the last result, as input to the next operation.
In the simple case, you need to keep the last result and the last value entered in a variable that is not changed on each loop(), as the counter and x variables in your code (but using more meaningful names may help understand what they are for). Nothing prevents you from storing the last result (or last value, but not both) in digitalPins. Looks boring to code, but also instructive.
P.S. just saw HazardsMind's comment, seems we are on the same track.
I'm struggling to do all of this.
This is my code for now.
/* Binary counting using 12 LEDs and a keypad to control
the increasing or decreasing rate by the value
of the key pressed*/
#include <Keypad.h>
int i;
int x;
int ledPin[12]={13,12,11,10,9,8,7,6,5,4,3,2};
int counter;
int firstKey;
int secondKey;
int mostSignificantBit;
int leastSignificantBit;
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
}
byte rowPins[ROWS] = {31, 33, 35, 37}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {39, 41, 43}; //connect to the column pinouts of the keypad
Keypad customKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
Serial.begin(9600);
for(i=0; i<12; i++){
pinMode(ledPin[i], OUTPUT); // sets the digital pins as output
}
void loop(){
char key = customKeypad.getKey();
if (firstKey=='1')
{
if (secondKey=='*'){
for(
}
else (secondKey=='#') {
for (
}
}
else if(firstKey=='2')
{
if (secondKey=='*'){
for(
}
else (secondKey=='#') {
for (
}
}
else if(firstKey=='3')
{
if (secondKey=='*'){
for(
}
else (secondKey=='#') {
for (
}
}
else if(firstKey=='4')
{
if (secondKey=='*'){
for(
}
else (secondKey=='#') {
for (
}
}
else if(firstKey=='5')
{
if (secondKey=='*'){
for(
}
else (secondKey=='#') {
for (
}
}
else if(firstKey=='6')
{
if (secondKey=='*'){
for(
}
else (secondKey=='#') {
for (
}
}
else if(firstKey=='7')
{
if (secondKey=='*'){
for(
}
else (secondKey=='#') {
for (
}
}
else if(firstKey=='8')
{
if (secondKey=='*'){
for(
}
else (secondKey=='#') {
for (
}
}
else if(firstKey=='9')
{
if (secondKey=='*'){
for(
}
else (secondKey=='#') {
for (
}
}
else (firstKey=='0')
{
if (secondKey=='*'){
for(
}
else (secondKey=='#') {
for (
}
}
}
I just wanted to make sure I am going in the right direction.
Can you check my code please to see what else is missing.
Some code examples would be useful.
I still don't know how to declare all the variables needed for my code.
Regards