//**********************************************************************
//
// Version YY/MM/DD Comments
// 1.01 18/12/01 Running code
//
// Adjust two potentiometers to clculate a sum value.
//
//**********************************************************************
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
// LCD pins: RS EN DB4 DB5 DB6 DB7
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
//i/o
const byte firstNumberPot = A0;
const byte secondNumberPot = A1;
//sram
int firstNumberPotReading;
int firstValue;
int secondNumberPotReading;
int secondValue;
//timing stuff
unsigned long firstValueMillis;
unsigned long secondValueMillis;
unsigned long printMillis;
//**********************************************************************
void setup()
{
Serial.begin(9600);
// set up the LCD's number of columns and rows:
lcd.begin(16, 2);
// 0123456789111111
// 012345
lcd.print("Pot. Calculator");
delay(2000);
} //END of setup()
//**********************************************************************
void loop()
{
//*********************************************
//adjust the first variable
firstNumberPotReading = analogRead(firstNumberPot);
//don't adjust
if (firstNumberPotReading > 450 && firstNumberPotReading < 550)
{
//do nothing
}
//slow increment
else if (firstNumberPotReading > 550 && firstNumberPotReading < 700)
{
if (millis() - firstValueMillis >= 500)
{
//restart timer
firstValueMillis = millis();
firstValue++;
}
}
//slow decrement
else if (firstNumberPotReading < 400 && firstNumberPotReading > 300)
{
if (millis() - firstValueMillis >= 500)
{
//restart timer
firstValueMillis = millis();
firstValue--;
}
}
//fast increment
else if (firstNumberPotReading > 700)
{
if (millis() - firstValueMillis >= 100)
{
//restart timer
firstValueMillis = millis();
firstValue++;
}
}
//fast decrement
else if (firstNumberPotReading < 300)
{
if (millis() - firstValueMillis >= 100)
{
//restart timer
firstValueMillis = millis();
firstValue--;
}
}
//*********************************************
//adjust the second variable
secondNumberPotReading = analogRead(secondNumberPot);
//don't adjust
if (secondNumberPotReading > 450 && secondNumberPotReading < 550)
{
//do nothing
}
//slow increment
else if (secondNumberPotReading > 550 && secondNumberPotReading < 700)
{
if (millis() - secondValueMillis >= 500)
{
//restart timer
secondValueMillis = millis();
secondValue++;
}
}
//slow decrement
else if (secondNumberPotReading < 400 && secondNumberPotReading > 300)
{
if (millis() - secondValueMillis >= 500)
{
//restart timer
secondValueMillis = millis();
secondValue--;
}
}
//fast increment
else if (secondNumberPotReading > 700)
{
if (millis() - secondValueMillis >= 100)
{
//restart timer
secondValueMillis = millis();
secondValue++;
}
}
//fast decrement
else if (secondNumberPotReading < 300)
{
if (millis() - secondValueMillis >= 100)
{
//restart timer
secondValueMillis = millis();
secondValue--;
}
}
//*********************************************
if (millis() - printMillis >= 500)
{
//restart timer
printMillis = millis();
Serial.print(firstValue);
Serial.print(" + ");
Serial.print(secondValue);
Serial.print(" = ");
Serial.println(firstValue + secondValue);
lcd.setCursor(0, 0);
//clear the line
// 111111
// 0123456789012345
lcd.print(" ");
lcd.setCursor(0, 0);
lcd.print(firstValue);
lcd.print(" + ");
lcd.print(secondValue);
lcd.print(" = ");
lcd.print(firstValue + secondValue);
}
} //END of loop()
//***