Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
1.2 kB
3
Indexable
Never
char volba = ' ';
byte predosly;
void setup() {
  Serial.begin(9600);
  
  DDRB = 0b00000111;          //ako vystup stlpce 1 2 3
  //PORTB =0b00000xxx;      // bity xxx ovladame tak, ze vzdy len jeden bit na log 0, ostatne na log 1
  DDRD &= 0b00001111;       //ako vstup riadky A B C D
  PORTD |=0b11110000;       // pullup rezistor
}

void loop() {
  
  prvy();
  druhy();
  treti();
  
  Serial.println(volba);
  
}

void prvy(){
  PORTB =0b00000110;       
  if((PIND&(1<<7)) == 0 ){ 
   volba = '1';}
  else if((PIND&(1<<6)) == 0 ){
   volba = '4';}
  else if((PIND&(1<<5)) == 0){
   volba = '7';}
  else if((PIND&(1<<4)) == 0){
   volba = '*';}
}

void druhy(){
  PORTB =0b00000101;       
  if((PIND&(1<<7)) == 0 ){ 
   volba = '2';}
  else if((PIND&(1<<6)) == 0 ){
   volba = '5';}
  else if((PIND&(1<<5)) == 0){
   volba = '8';}
  else if((PIND&(1<<4)) == 0){
   volba = '0';}
}

void treti(){
  PORTB =0b00000011;       
  if((PIND&(1<<7)) == 0 ){ 
   volba = '3';}
  else if((PIND&(1<<6)) == 0 ){
   volba = '6';}
  else if((PIND&(1<<5)) == 0){
   volba = '9';}
  else if((PIND&(1<<4)) == 0){
   volba = '#';}
}