Home Code Another TM1638 button example

Another TM1638 button example

by shedboy71
[lebox id="1"]

Another TM1638 example, this time when you press a button a random sequence of LEDs will be lit

The previous project is here for connection information

Code

[c]

#include <TM1638.h>
// define a module on data pin 8, clock pin 9 and strobe pin 10
TM1638 module(8, 9, 10);

byte buttons;
void setup()
{
}

void loop()
{
//get the button
//S1 = 1, S2 = 2, S3 = 4, S4 = 8
//S5 = 16, S6 = 32, S7 = 64, S8 = 128
buttons=module.getButtons();
//module.setDisplayToDecNumber(buttons,0,false);
//module.setLEDs(buttons);
switch (buttons)
{
case 0:
module.setLEDs(0x00);
break;
case 1:
module.setLEDs(0x7F);
break;
case 2:
module.setLEDs(0x0A);
break;
case 4:
module.setLEDs(0xEF);
break;
case 8:
module.setLEDs(0x0F);
break;
case 16:
module.setLEDs(0xBA);
break;
case 32:
module.setLEDs(0xEE);
break;
case 64:
module.setLEDs(0xDF);
break;
case 128:
module.setLEDs(0xCD);
break;
default:
module.setLEDs(0x00);
break;

}
}

[/c]

Share
[lebox id="2"]

You may also like