Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <TM1638.h>
- // Wemos D1 Mini = Data:D2,Clock:D5,Strobe:D6
- TM1638 module(4, 14, 12);
- const char alpha[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'x', 'y', 'z'};
- int pos = 8;
- //Demo how you can define place of dot
- //Dot will move from left to right and index number for the place will be shown.
- void scrollDots() {
- for (int i = 0; i < 8; i++)
- {
- module.clearDisplay();
- //Move dot one place to right
- module.setDisplayToDecNumber(i, 128 >> i);
- delay(1000);
- }
- delay(2000);
- }
- //Scroll all alphabets
- void scrollAlpha() {
- String s = "";
- for (int i = 0; i < 26; i++)
- {
- module.clearDisplay();
- //When we have 8 characters on display, start to scroll them.
- if (i > 8) {
- s.remove(0, 1);
- }
- s = s + alpha[i];
- module.setDisplayToString(s);
- delay(1000);
- }
- delay(2000);
- }
- void setup() {
- Serial.begin(9600);
- /** Set the display (segments and LEDs) active or off and intensity (range from 0-7). */
- module.setupDisplay(true, 0);
- scrollDots();
- scrollAlpha();
- module.clearDisplay();
- }
- //Move leds with first and second button
- void loop() {
- byte keys = module.getButtons();
- int a = keys;
- delay(100);
- switch (keys) {
- case 1 :
- pos = pos >> 1;
- break;
- case 2 :
- pos = pos << 1;
- break;
- //Other keys are cases 4,8,16,32,64,128
- //If you need to check if second and third buttons are bot pressed, make case for (2+4)=6
- }
- //Dont let red dot escape from the playground
- if (pos > 128) pos = 1;
- if (pos < 1) pos = 128;
- module.setLEDs(pos);
- }
Add Comment
Please, Sign In to add comment