How do I use a potentiometer to speed up program?

Hi,
(I am using an Arduino Uno for this project). I am making a music metronome that beats a steady rhythm to play to. I'm using a small buzzer to do the beat for me.(3-24V DC) I also have a seven segment display that counts to four then goes back to one to the beat. I want to use a potentiometer so that I can turn it clockwise and the beat speeds up, and when you turn it counterclockwise it slows it down. How do I program the arduino to do this. I've tried googling this but I can't find anything. Here is the program that does all my ticking and stuff already for me, how do I program in the pot around this?

int ibuzz = 11;


void setup() {   
  pinMode(11, OUTPUT);  
  pinMode(2, OUTPUT);  
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  digitalWrite(9, 0);  // start with the "dot" off
}

void loop() {
  
   // write '1'
 digitalWrite(2, 0);
 digitalWrite(3, 1);
 digitalWrite(4, 1);
 digitalWrite(5, 0);
 digitalWrite(6, 0);
 digitalWrite(7, 0);
 digitalWrite(8, 0);
  analogWrite(11, 100);
 delay(10);
 analogWrite(11, 0);
 delay(1000);
  // write '2'
 digitalWrite(2, 1);
 digitalWrite(3, 1);
 digitalWrite(4, 0);
 digitalWrite(5, 1);
 digitalWrite(6, 1);
 digitalWrite(7, 0);
 digitalWrite(8, 1);
  analogWrite(11, 5);
 delay(10);
 analogWrite(11, 0);
 delay(1000);
 // write '3'
 digitalWrite(2, 1);
 digitalWrite(3, 1);
 digitalWrite(4, 1);
 digitalWrite(5, 1);
 digitalWrite(6, 0);
 digitalWrite(7, 0);
 digitalWrite(8, 1);
  analogWrite(11, 5);
 delay(10);
 analogWrite(11, 0);
 delay(1000);

 // write '4'
 digitalWrite(2, 0);
 digitalWrite(3, 1);
 digitalWrite(4, 1);
 digitalWrite(5, 0);
 digitalWrite(6, 0);
 digitalWrite(7, 1);
 digitalWrite(8, 1);
  analogWrite(11, 5);
 delay(10);
 analogWrite(11, 0);
 delay(1000);

Thanks in advance!
Gilbert

Might help to spell it correctly - potentiometer.

5V to 1 outer leg, other outer leg to Gnd, middle leg to an analog input.

Read the level on the pot at the top of void loop:
potValue = analogRead(A0); // or whatever you are connected to.

This will be a value from 0 to 1023.
Looks like you could use that value in place of the delay(1000)s you have now:
delay(potValue);

1 Like

Thanks, Works great!

Not bad for making it up on the fly, eh?

1 Like