Hello, I am trying to control the blink speed of an arduino uno using a potentiometer. I am basing this off of a previous topic (Using Potentiometer to Control LED Blink Speed - Exhibition - Arduino Forum). Here is the code that I have been using thus far, ignore the LCD screen stuff, it works.
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7);
int potpin = A2;
int ledpin = 13;
int val;
int lastChange;// the time of changing pin state
void setup()
{
pinMode(ledpin, OUTPUT);
val = map(analogRead(potpin), 0, 1023, 500, 5);
lcd.setBacklightPin(3,POSITIVE);
lcd.setBacklight(HIGH);
lcd.begin(16, 2);
lcd.setCursor(0,0);
Serial.begin(9600);
lcd.print("RPM = ");
lcd.setCursor(0,1);
lcd.print("Temp (F) = ");
lcd.setCursor(20,0);
lcd.print("Bearing Life = ");
}
void loop()
{
lastChange = millis();
digitalWrite(ledpin, HIGH);
while(lastChange + val <= millis()) // loop while there's time for it :)
{
val = map(analogRead(potpin), 0, 1023, 500, 5); // read the value every time
Serial.println(val);
}
// the same here:
digitalWrite(ledpin, LOW);
lastChange = millis();
while(lastChange + val <= millis())
{
val = map(analogRead(potpin), 0, 1023, 500, 5);
Serial.println(val);
}
}
The potentiometer is not changing the speed and I'm not sure what the issue is. I am having trouble including some images of the way it is connected, due to file size restrictions, so please let me know if those would be helpful. Thank you.