Go Down

Topic: selecting numbers with a potmeter (Read 338 times) previous topic - next topic

hankr99

hello y'all, im doing a project on my own and im trying to make a safe . You have to select 4 numbers ranging from 0-25 . I want to use a potmeter and when u turn the knob it goes through the range of numbers and then confirm the numbers with a button , can anyone help me in the right direction?

thanks in advance

PaulS

Quote
can anyone help me in the right direction?
The right direction would obviously be to use analogRead() to read the potentiometer value and digitalRead() to read the switch states. Of course, this approach presupposes that you know how to connect the switch and potentiometer to the Arduino.
The art of getting good answers lies in asking good questions.

wvmarle

Unless this is a paid job, you better ask a mod to move this to the Project Guidance forum.
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

hankr99

The right direction would obviously be to use analogRead() to read the potentiometer value and digitalRead() to read the switch states. Of course, this approach presupposes that you know how to connect the switch and potentiometer to the Arduino.
yea i already got that the serial monitor gives me the numbers from 0-25 but with the selecting part im still lost

wvmarle

So what do you have (post code) and where does it go wrong?
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

hankr99

//
So what do you have (post code) and where does it go wrong?
So what do you have (post code) and where does it go wrong?
int pMin = 14; 
int pMax = 948;
int x = 0; 
void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
x = analogRead(A0);

  Serial.print(x); 

  x = map(x, pMin, pMax, 0, 24);
  Serial.print("\t");
  Serial.println(x);   delay(100);
}

this shows in the serial monitor numbers between 0-25 now i have to write a code that i can select 4 numbers with 4 presses on a button but i have no idea where to start , these 4 numbers work like a password , so when the 4 numbers are correct a green light lights up and if u choose 4 wrong numbers a redlight shows up

wvmarle

Create an array, then upon reading a button press you take an analogRead() and place the number in the array.

Code: [Select]

byte selectedNumber[4];
byte counter = 0;
void loop() {
  if (digitalRead(BUTTON_PIN) == LOW) {
    int x = analogRead(A0);
    selectedNumber[counter] = map(x, pMin, pMax, 0, 24);
    counter++;
    delay(100); // for button bounce
  }
  if (counter >= 4) {
    do_check_code();
  }
}
Quality of answers is related to the quality of questions. Good questions will get good answers. Useless answers are a sign of a poor question.

Go Up