Hello All! I am completely new to electronics and programming. I am thoroughly loving learning about this stuff. And I feel like I have learned a lot in a short time. I have however run into a situation I cannot figure out on my own, and my googling has not helped. I have written the code below that will read the position of a potentiometer and report it on the lcd as a percentage and also let the potentiometer control a fan. This lets me see what percentage of power the fan is running off of. I know its simple but I feel extremely happy about being able to figure just that all out haha. My problem is that after I go all the way up to 100% and turn back down, it will show percent signs where numbers used to be. ie. 2%%% when it was 100%. Could someone point me in the right direction on how to fix this?
Thanks for any help!
Here's the code.
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int tipcontrolPin = 9; // TIP 120 pin controlling fan speed
int potcontrolPin = A0; // Reads Potentiometer posistion
int potval; // Value of potentiometer
int lcdpercentageVal; // Fan speed percentage converted from raw to percentage format
int fanspeedVal; // Value to control fan speed
void setup()
{
lcd.begin(16,2);
lcd.print("Fan Sketch Test");
delay(5000);
lcd.clear();
pinMode(tipcontrolPin, OUTPUT);
}
void loop()
{
{
potval = analogRead(potcontrolPin);
lcdpercentageVal = map(potval, 0, 1024, 0, 101);
lcd.setCursor(0,0);
lcd.print("Fan Speed");
lcd.setCursor(0,1);
lcd.print(lcdpercentageVal);
lcd.print("%");
}
{
fanspeedVal = map(potval, 0, 1024, 0, 255);
analogWrite(tipcontrolPin, fanspeedVal);
}
delay(100);
}