Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h> //import lcd library
- #include <Keypad.h> //import keypad library
- LiquidCrystal lcd(5, 4, 3, 2, 1, 0); //lcd pins
- const byte ROWS = 4; // four rows
- const byte COLS = 3; // three columns
- int latchPin = A5; //Pin connected to ST_CP of 74HC595
- int clockPin = A2; //Pin connected to SH_CP of 74HC595
- int dataPin = A1; ////Pin connected to DS of 74HC595
- char keys [ROWS] [COLS] = {
- {'1', '2', '3'},
- {'4', '5', '6'},
- {'7', '8', '9'},
- {'X', '0', 'o'} };
- byte rowPins[ROWS] = {9 ,8 ,7 ,6}; //connect keypad ROW1, ROW2, ROW3, ROW4 to these arduino pins
- byte colPins[COLS] = {13, 12, 11}; //connect keypad COL1, COL2, COL3 to these arduino pins
- //create the keypad
- Keypad myKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
- //variables declaration
- String num1, num2;
- int ans;
- void setup(){
- pinMode(latchPin, OUTPUT);
- pinMode(clockPin, OUTPUT);
- pinMode(dataPin, OUTPUT);
- //set lcd welcome screen
- lcd.begin(16,2);
- lcd.setCursor(2,0);
- lcd.print("vloz hodnotu");
- lcd.setCursor(3,1);
- lcd.print("el. odporu");
- }
- void loop(){
- char key = myKeypad.getKey();
- if (key != NO_KEY && (key == '1' || key == '2' || key == '3' || key == '4' || key == '5' || key == '6' || key == '7' || key == '8' || key == '9' || key == '0')){
- num1 = num1 + key;
- int numLength = num1.length();
- lcd.clear();
- ans = num1.toInt(); //from strings to integer
- switch (ans)
- {
- case 1:
- ans = 0b00000001;
- break;
- case 2:
- ans = 0b00000010;
- break;
- // atd.
- }
- lcd.print(ans); //print answer
- //Ans je vlastne hodnota z klavesnice. Ak ans=2 tak sa ledky sa rozsvietia v poradi 01000000 (cize ide o prevod do bin. kodu)
- //tuto by som potreboval predefinovat, resp. priradit hodnote z klavesnice inu binarnu hodnotu. Skusal som vytvarat matice hodnot ale nic.
- digitalWrite(latchPin, LOW);
- shiftOut(dataPin, clockPin, LSBFIRST, ans); // problem bude mozno ze musis posielat ako MSBFIRST
- digitalWrite(latchPin, HIGH);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement