Components and supplies
1
Arduino Nano R3
1
Arduino UNO
Apps and platforms
1
Arduino IDE
Project description
Code
wuerfel2_v3.ino
arduino
Comments
Only logged in users can leave comments
Components and supplies
Arduino Nano R3
Arduino UNO
Apps and platforms
Arduino IDE
Project description
Code
wuerfel2_v3.ino
arduino
1// Program: LED Dice version 3 2 3// setup the pins 4// pin number of the first LED 5int PinErsteLED=2; 6 7// pin number of the button 8int PinTaster=9; 9 10// LED order 11// 1 2 12// 3 7 4 13// 5 6 14int wuerfelBild[8][7]= 15 {{0,0,0,0,0,0,0}, //0 = all LED's off 16 {0,0,0,0,0,0,1}, //1 17 {0,1,0,0,1,0,0}, //2 18 {1,0,0,0,0,1,1}, //3 19 {1,1,0,0,1,1,0}, //4 20 {1,1,0,0,1,1,1}, //5 21 {1,1,1,1,1,1,0}, //6 22 {1,1,1,1,1,1,1}}; //7 = all LED's on 23 24int lauflichtmax=6; 25int lauflicht[6]= { 1, 7, 6, 2, 7, 5}; //LED number 26int lauflichtpause[6]={ 60,100,180,180,100, 60}; //time in ms 27 28 29void setup() { 30 31 // define all pins as output 32 for (int i=PinErsteLED;i<=PinErsteLED+6;++i) 33 pinMode(i,OUTPUT); 34 35 // pin of the button 36 pinMode(PinTaster,INPUT); 37} 38 39// function to show the result 40void ZeigeZahl(int zahl) { 41 for (int i=0;i<=6;++i) 42 digitalWrite(i+PinErsteLED,wuerfelBild[zahl][i]?HIGH:LOW); 43} 44 45void loop() { 46//declare variables 47int i,j,zufall; 48unsigned long spezial; 49 50 ZeigeZahl(7); //all LED's on 51 delay(1000); // wait 1 second 52 // start animation 53 i=0; 54 do { 55 i=i+1; 56 if (i>6) {i=1;} 57 delay(500); 58 ZeigeZahl(i); //show number 59 } while (digitalRead(PinTaster)==HIGH); //wait til key is pressed 60 61 // start dicing 62 do { 63 //setup 64 zufall=0; 65 i=0; 66 spezial=millis(); 67 do { 68 zufall=zufall+1; //used for random number 69 i=i+1; 70 if (i>=lauflichtmax) {i=0;} //if i is lauflichtmax, then set i to 0, so i is in 0..6 71 delay(lauflichtpause[i]); //wait 72 73 ZeigeZahl(0); // all LED's off 74 digitalWrite(PinErsteLED+lauflicht[i]-1,HIGH); 75 76 } while (digitalRead(PinTaster)==LOW); //repeat until the button is releashed 77 78 zufall=zufall%6; //result is number 0..5 79 spezial=millis()-spezial; 80 if ((spezial>2000) and (spezial<3000)) { 81 if (zufall!=5) {zufall=millis()%6;} //dice again, if no 6! 82 } 83 ZeigeZahl(zufall+1); //show number 84 85 while (digitalRead(PinTaster)==HIGH); //wait til next keypress 86 } while (1==1); //repeat endless 87} 88 89 90 91
Comments
Only logged in users can leave comments