Components and supplies
UNO WIFI R4
Push Button
Apps and platforms
Arduino IDE 2.3.2
Project description
Code
UNO WIFI R4 matrix dice
cpp
1/*This code will play dice using arduino uno r4 wifi built in display. 2 Uses random number generator. 3 Push button should be connected between gnd and pin12. 4 Good luck! 5*/ 6 7//you should have or download this library 8#include "Arduino_LED_Matrix.h" 9ArduinoLEDMatrix matrix; 10long randNumber; 11 12void setup() { 13//this will set pin12 on HIGH and sense if it is grounded by push button 14pinMode(12, INPUT_PULLUP); 15 16 17byte dice[8][12] = { 18 { 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0 }, 19 { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 20 { 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1 }, 21 { 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1 }, 22 { 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 1 }, 23 { 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0 }, 24 { 1, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1 }, 25 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } 26}; 27 28const uint32_t smile[] = { 29 0x19819, 30 0x80000001, 31 0x81f8000 32}; 33 34 //starts matrix 35 matrix.begin(); 36 37 //pause and getting some value from analog pin 4 (value is changing -floating, because nothing is connected on pin a4) 38 // it helps later to choose random number 39 delay(50); 40 randomSeed(analogRead(4)); 41 42 //start image 43 matrix.loadFrame(smile); 44 delay(700); 45 //second start image 46 matrix.renderBitmap(dice, 8, 12); 47 48} 49 //you can see pattern of leds in matrix (1- led is on, 0- led is off) 50byte one[8][12] = { 51 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 52 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 53 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 54 { 0, 0, 0, 0, 0, 1, 1, 0, 0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 0 }, 87 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 88 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 89 { 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0 }, 90 { 0, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 0 }, 91 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } 92}; 93 94byte five[8][12] = { 95 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 96 { 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0 }, 97 { 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0 }, 98 { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 }, 99 { 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0 }, 100 { 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0 }, 101 { 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0 }, 102 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } 103}; 104 105byte six[8][12] = { 106 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 107 { 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0 }, 108 { 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0 }, 109 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 110 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }, 111 { 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0 }, 112 { 0, 0, 1, 1, 0, 1, 1, 0, 1, 1, 0, 0 }, 113 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 } 114}; 115 116 117 118 119 120 121void loop(){ 122 123 //this part of code will check push button on d12 and if is pressed will generate random number between 1 and 6 inclusive 124 if (!digitalRead(12)){ 125 randNumber = random(1, 7); 126 } 127 //deciding wich number is generated and sending to matrix display 128 switch (randNumber) { 129 case 1: 130 matrix.renderBitmap(one, 8, 12); 131 delay(10); 132 break; 133 case 2: 134 matrix.renderBitmap(two, 8, 12); 135 delay(10); 136 break; 137 case 3: 138 matrix.renderBitmap(three, 8, 12); 139 delay(10); 140 break; 141 case 4: 142 matrix.renderBitmap(four, 8, 12); 143 delay(10); 144 break; 145 case 5: 146 matrix.renderBitmap(five, 8, 12); 147 delay(10); 148 break; 149 case 6: 150 matrix.renderBitmap(six, 8, 12); 151 delay(10); 152 break; 153 } 154 155}
Downloadable files
Dice shematic
this is dice schematic it is a pdf file
dice shematic.pdf
dice schematic in picture
its same as pdf
dice shematic (in picture).png
Comments
Only logged in users can leave comments