+/*
+very basic demo to demostrate how easy drive a tm1638 with this library.
+A tm1638 has a led matrix 8x8 (64 led) connected and 25 switches, only 3 pins
+needed by arduino. The demo will detect switches and turn on/off corrispondent led
+(from 0 to 24), the other leds are free to blink. You will notice that everithing works
+pretty fast and with any disturb between key scan and leds even if share same pins!
+I've noticed that apparently no debounce it's needed.
+*/
+
 #include <TM16xxRAW.h>
 
 

TM16xxRAW tm(3,4,5);


volatile uint32_t pbutton = 0;


void setup() {
  Serial.begin(38400);
  //optional:brightness(0:7))
  tm.begin();
}


void loop() {
  randomLed2();
  uint32_t pbutton = tm.getButtons();
  if (pbutton != 0) {
    for (byte i=24; i>=0; i--){
      if (bitRead(pbutton,i) == 1){
        Serial.println(i+1,DEC);
        break;
      }
    }
  }
}



  tm.setLed(led,val,true);  
  delay(5);
}

void ledefx1(byte count){
  //  if (tm.getLed(count) == 1){
  //    tm.setLed(count,0,true);  
  //  } 
  //  else {
  //    tm.setLed(count,1,true);  
  //  }


  for (byte i=3;i<8;i++){
    tm.setColumn(i,0);
  }
  tm.setLed(count,1,false);
  tm.updateColumn();
}


