Arduino Calculator With Only 1 Button and Potentiometer and 4 Digit LED Display

can anyone help me with coding for the Arduino calculator that function only on two things, Potentiometer to select a value min -10 and max 10 then press button 1 to select operator (=,-,*,/) again using the potentiometer to select that, then again pressing the same button1 to select second value and providing the answer on the 4 digit LED screen.

My first time using Arduino forms, hopefully you guys can help me out

Can you make the parts work ?
Make a few test-sketches. One for the potentiometer, one for the button, and one for the LED display.
Use the serial monitor to show the result.

What is your programming experience ? Any language is okay.
What have you made with an Arduino so far ?

I don't have much of a programming experience and so far I've been able to make use of the potentiometer to show the value from lowest -10 to highest 10. Now I don't know how make button 1 save that value for later use and then make the potentiometer display the operator a(+), s(-), t(*) and d(/) and after selecting and saving the operator, i have to click the same button 1 to select the second value between -10 and 10 and then press the button again to show the answer.

#include "Display.h"
const int POTENTIOMETER = A0;
const int BUTTON1 = 9;

const int MinV = -10; // This is the Minimum value the potentiometer should show at its lowest.
const int MaxV = 10; // This is the Maximum value the potentiometer should show at its highedt.

int FNum; // Assigned an int for the first number that has to be inputed.
int SNum; // Assigned an int for the second number that has to be inputed.
float Answer;  // Assigned a float for the answer becasue it may contain decimal points.
String op; // Operator
String a; // Short for Addition (+)
String s; // Substract (-)
String t; // Times or Multiply (*)
String d; // Divide (/)

void setup() {
int knobvalue1() // The value of the direction the potentiometer is facing. 
  int value1 = analogRead(POTENTIOMETER);
  int range1 = map(value1, 0, 1023, MinV,MaxV);
  return range1;

void loop() {
int range1 = knobvalue1();;

I think you need the State Change Detection:
That example increments a variable 'buttonPushCounter', that is the moment where you need to store the value.

Can you press Ctrl+T in the Arduino IDE ?
After that, make the text layout of the code look better. Use the same style, put every indent, every new line, everything at the right place.

The pinMode() is not needed when a analog input is used. See the example of analogRead(): analogRead() - Arduino Reference.
You need a pinMode() for the digital input of the button.

let me try that and get back to you. Thanks a lot for your help. Really grateful

Hey, I looked trough the links you sent but i still haven't been able to come up with even 1 new line of code mainly because of my 0 coding experience.
Maybe there are some other links that could help me with making the potentiometer show the operators (a, s, t, d) (letter and not +, -, * , / because the 4 digit led can't show it.

so when i press the button, the led display reading change from the range of -10 to 10 (of course after saving it for use later on) and change display to the operators, save the selected operator and then again display the range -10 to 10 for the second value.

So firstly if i select 5, then i select the operator + and second value as 10 and then get the answer 15 on the led display

Did you try the State Change Detection sketch ?

I had a look through it and it confused me on where to add the potentiometer readings

Try it. See what it does.

I tried the code in a new window, it doesn't do much. it just randomly turns the led on and off. pressing any button or moving the potentiometer doesn't do anything.

I meant the State Change Detection sketch. Connect it as shown and try that sketch. Open the serial monitor. Can you see the increasing count ?

This build is impossible for me as its my first time coding. I will join some code parts to make it display the number even if it can't calculate. Hopefully that way I'll get some marks and won't have to repeat first semester.

Could you please tell me how I could make the potentiometer display alphabets on the four digit LED. It only needs to display a, s, t and d. only 1 alphabet at a time.

So how i did this ( int range1 = map(value1, 0, 1023, -10,10); ) where when i put the potentiometer on the left at 0 its shows -10 then i move it, it goes -9, -8 .... 0,1,2 .... and so one. so i need it to shows the 4 alphabets the same way.

could you please just help me with that lastly. I'll just give in those 2 codes separately. I don't have much time left

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.