Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LedControl.h>
- #define DATA_pin 12
- #define CS_pin 11
- #define CLK_pin 10
- #define BTN_pin 2
- #define LED_pin 13
- byte numbers[][6] = {
- {
- B00000000,
- B00000000,
- B00010000,
- B00000000,
- B00000000
- },
- {
- B00000000,
- B01000000,
- B00000000,
- B00001000,
- B00000000
- },
- {
- B00000000,
- B01000000,
- B00100000,
- B00010000,
- B00000000
- },
- {
- B00000000,
- B00101000,
- B00000000,
- B00101000,
- B00000000
- },
- {
- B00000000,
- B00101000,
- B00010000,
- B00101000,
- B00000000
- },
- {
- B00000000,
- B00101000,
- B00101000,
- B00101000,
- B00000000
- }
- };
- LedControl LED_CTRL(DATA_pin, CLK_pin, CS_pin, 1);
- int buttonState = 0;
- unsigned long delaytime = 100;
- void setup() {
- Serial.begin(9600);
- LED_CTRL.shutdown(0, false);
- LED_CTRL.setIntensity(0, 8);
- LED_CTRL.clearDisplay(0);
- pinMode(BTN_pin, INPUT);
- pinMode(LED_pin, OUTPUT);
- randomSeed(analogRead(0));
- }
- void loop() {
- LED_CTRL.clearDisplay(0);
- buttonState = digitalRead(BTN_pin);
- if (buttonState == HIGH) {
- int randomNum = random(6) + 1;
- displayNumber(randomNum);
- delay(20 * delaytime);
- }
- }
- void displayNumber(int number) {
- for (int i = 0; i < 6; i++) {
- LED_CTRL.setRow(0, i, numbers[number-1][i]);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement