Kod:
#include <LiquidCrystal.h>
// Initialize the library with the numbers of the interface pins
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
//States for the menu.
int currentMenuItem = 0;
int lastState = 0;
//Wartości kolorów
int czarny=0;
int brazowy=1;
int czerwony=2;
int pomaranczowy=3;
int zolty=4;
int zielony=5;
int niebieski=6;
int fioletowy=7;
int szary=8;
int bialy=9;
//Tolerancja w %
int brazowy1=1;
int czerwony1=2;
int pomaranczowy1=15;
int zielony1=0.5;
int niebieski1=0.25;
int fioletowy1=0.1;
int zloty=5;
int srebrny=10;
int brak=20;
int A = 0;// Dziesiątki
int B = 0;// Jedności
int C = 0;// Wynik A+B
int D = 0;// Mnożnik
int E = 0;// Tolerancja
int F = 0;// Wynik C*D
void setup() {
//Set the characters and column numbers.
lcd.begin(16, 2);
//Print default title.
clearPrintTitle();
}
void loop() {
//Call the main menu.
mainMenu();
}
void mainMenu() {
//State = 0 every loop cycle.
int state = 0;
//Refresh the button pressed.
int x = analogRead (0);
//Set the Row 0, Col 0 position.
lcd.setCursor(0,0);
if (x < 100) {
//Right
} else if (x < 200) {
//Up
state = 1;
} else if (x < 400){
//Down
state = 2;
} else if (x < 600){
//Left
} else if (x < 800){
//Select
state = 3;
}
//If we are out of bounds on th menu then reset it.
if (currentMenuItem < 0 || currentMenuItem > 4) {
currentMenuItem = 0;
}
if (state != lastState) {
if (state == 1) {
//If Up
currentMenuItem = currentMenuItem - 1;
displayMenu(currentMenuItem);
} else if (state == 2) {
//If Down
currentMenuItem = currentMenuItem + 1;
displayMenu(currentMenuItem);
} else if (state == 3) {
//If Selected
selectMenu(currentMenuItem);
}
lastState = state;
}
//Small delay
delay(5);
}
void displayMenu(int x) {
switch (x) {
case 1:
clearPrintTitle();
lcd.print ("- KOD REZYSTOROW");
lcd.setCursor(0,1);
lcd.print (" ");
break;
}
}
void clearPrintTitle() {
lcd.clear();
lcd.setCursor(0,0);
lcd.print(" * KALKULATOR *");
lcd.setCursor(0,1);
lcd.print(" * REZYSTOROW *");
lcd.setCursor(0,0);
}
void selectMenu(int x) {
switch (x) {
case 1:
clearPrintTitle();
lcd.setCursor(0,0);
lcd.print ("Pasek: ");
lcd.setCursor(0,1);
lcd.print ("Kolor: ");
}
}