Κώδικας:
/* hey, this is a simple code to make your arduino read
the value of a potentiometer and display it in percentage form on
a 16 X 2 LCD screen. I am pretty new at this so sorry if this code
is terrible or if i have no idea what i'm talking about in the
comments.
the circuit(pasted from examples):
* LCD RS pin to digital pin 12
* LCD Enable pin to digital pin 11
* LCD D4 pin to digital pin 5
* LCD D5 pin to digital pin 4
* LCD D6 pin to digital pin 3
* LCD D7 pin to digital pin 2
* LCD R/W pin to ground
* 10K resistor:
* ends to +5V and ground
* wiper to LCD VO pin (pin 3)
* Potentiometer attached to analog input 0
* Potentiometer attached to analog input 1
* center pin of the potentiometer to the analog pin
* one side pin (either one) to ground
* the other side pin to +5V
*/
//=======================================================================INCLUDES
#include <LiquidCrystal.h> // include the LCD library
//=======================================================================DEVICE SETUP
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//=======================================================================VARIABLES
int potPin = A0; //Potentiometer input pin
int potValue1 = 0;
int potValue2 = 0; // final display variable
int poLPin = A1; //Potentiometer input pin
int poLValue3 = 0;
int poLValue4 = 0; // final display variable
//=======================================================================SETUP
void setup()
{
lcd.begin(16, 2); // lcd rows and columns
// set up the LCD's number of columns and rows:
// Print a message to the LCD.
lcd.print("Rotor Controller");
delay(5500);
lcd.clear();
}
//=======================================================================MAIN LOOP
void loop()
{
// read then divide the input(max 1020 in this case) by 10
potValue1 = analogRead(potPin) / 1.87;
// divide by 1.02 to get percentage
potValue2 = potValue1 / 1;
if(potValue2<10)
{
lcd.setCursor(0,0);
lcd.print("00");
lcd.print(potValue2);
}
else if((potValue2>9) && (potValue2<100))
{
lcd.setCursor(0,0);
lcd.print("0");
lcd.print(potValue2);
}
else if(potValue2>99)
{
lcd.setCursor(0,0);
lcd.print(potValue2);
}
//print the percent symbol at the end
lcd.print((char)223);
lcd.print(" Azimuth");
//=======================================================================
// read then divide the input(max 1020 in this case) by 10
poLValue3 = analogRead(poLPin) / 7.48;
// divide by 1.02 to get percentage
poLValue4 = poLValue3 / 1;
// set cursor to second row, first column
if(poLValue4<10)
{
lcd.setCursor(0,1);
lcd.print("00");
lcd.print(poLValue4);
}
else if((poLValue4>9) && (poLValue4<100))
{
lcd.setCursor(0,1);
lcd.print("0");
lcd.print(poLValue4);
}
else if(poLValue4>99)
{
lcd.setCursor(0,1);
lcd.print(poLValue4);
}
//print the percent symbol at the end
lcd.print((char)223);
lcd.print(" Elevation");
//wait 0.1 seconds
delay(100);
//wipe the extra characters
lcd.print(" ");
delay(1);
}
Τώρα είσαι ΟΚ, χτίζεται κανονικά.