View difference between Paste ID: Wbm7zVZu and Uh4xTjLQ
SHOW: | | - or go back to the newest paste.
1
  #include <LiquidCrystal.h> //import lcd library
2
  #include <Keypad.h> //import keypad library
3
4
  LiquidCrystal lcd(5, 4, 3, 2, 1, 0); //lcd pins
5
  const byte ROWS = 4; // four rows
6
  const byte COLS = 3; // three columns
7
8
  int latchPin = A5;  //Pin connected to ST_CP of 74HC595
9
  int clockPin = A2;  //Pin connected to SH_CP of 74HC595
10
  int dataPin = A1;  ////Pin connected to DS of 74HC595
11
12
  char keys [ROWS] [COLS] = {
13
     {'1', '2', '3'},
14
     {'4', '5', '6'},
15
     {'7', '8', '9'},
16
     {'X', '0', 'o'} };
17
  
18
  byte rowPins[ROWS] = {9 ,8 ,7 ,6}; //connect keypad ROW1, ROW2, ROW3, ROW4 to these arduino pins
19
  byte colPins[COLS] = {13, 12, 11}; //connect keypad COL1, COL2, COL3 to these arduino pins
20
21
  //create the keypad
22
  Keypad myKeypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
23
24
  //variables declaration
25
  String num1, num2;
26
  int ans;
27
28
  void setup(){
29
  
30
  pinMode(latchPin, OUTPUT);
31
  pinMode(clockPin, OUTPUT);
32
  pinMode(dataPin, OUTPUT);
33
  
34
  //set lcd welcome screen  
35
  lcd.begin(16,2);
36
  lcd.setCursor(2,0);
37
  lcd.print("vloz hodnotu");
38
  lcd.setCursor(3,1);
39
  lcd.print("el. odporu");
40
 
41
}
42
43
void loop(){
44
  char key = myKeypad.getKey();
45
  
46
    if (key != NO_KEY && (key == '1' || key == '2' || key == '3' || key == '4' || key == '5' || key == '6' || key == '7' || key == '8' || key == '9' || key == '0')){
47
          num1 = num1 + key; 
48
          int numLength = num1.length();
49
          lcd.clear();
50
51
          ans = num1.toInt(); //from strings to integer
52
53
	  switch (ans)
54
	  {
55
		case 1:
56
		  ans = 0b00000001;
57-
    shiftOut(dataPin, clockPin, LSBFIRST, ans);
57+
		break;
58
59
		case 2:
60
		  ans = 0b00000010;
61
		break;
62
63
		// atd.
64
	  }
65
66
          lcd.print(ans); //print answer
67
          
68
 //Ans je vlastne hodnota z klavesnice. Ak ans=2 tak sa ledky sa rozsvietia v poradi 01000000 (cize ide o prevod do bin. kodu)
69
 //tuto by som potreboval predefinovat, resp. priradit hodnote z klavesnice inu binarnu hodnotu. Skusal som vytvarat matice hodnot ale nic.
70
71
    digitalWrite(latchPin, LOW);
72
    shiftOut(dataPin, clockPin, LSBFIRST, ans);  // problem bude mozno ze musis posielat ako MSBFIRST
73
    digitalWrite(latchPin, HIGH);
74
    
75
76
    
77
     }
78
    }