bravetea / dice_thrower_v2 Goto Github PK
View Code? Open in Web Editor NEWNew & Improved Dice Thrower
License: MIT License
New & Improved Dice Thrower
License: MIT License
How can I interrupt the void loop() and to have it wait until the next push of the button?
Right now you use dNum * 1000 + 4000 which is derived from d6 using 10000 possibilities, but it doesn't scale. d4 is 8000 possibilities and maybe it should be
dNum * 1000 + (dNum * 1000) * 0.66) )to have it accurately scale to 10000.
Don't forget though that 10000 was a somewhat arbitrary number when you first picked it.
A suggestion of @ggerritsen
write a function to replace
digitalWrite(ledMatrix[row][col], HIGH);
e.g.
void ledOn(int x)
{
digitalWrite(x, HIGH);
}
Dn = D6 or D10 (n is 6 or 10)
Add a variable so someone just needs to input the Dn number and it wil work accordingly.
e.g.
int Dn = 6;
....
mapChange = map(num, 1, 10000, 1, Dn);
NB Don't forget to add additional if statements for 7,8,9.
Which of the two ways should I go for?
you can write void four() in two ways:
1.
void four()
{
digitalWrite(ledMatrix[0][0], HIGH);
digitalWrite(ledMatrix[2][0], HIGH);
digitalWrite(ledMatrix[0][2], HIGH);
digitalWrite(ledMatrix[2][2], HIGH);
}
or
void four()
{
for (int row = 0; row < 3; row++)
{
if (row == 1)
{
continue;
}
digitalWrite(ledMatrix[row][0], HIGH);
digitalWrite(ledMatrix[row][2], HIGH);
}
}
I had a huge problem which would give me seemingly incorrect random numbers. The Serial Monitor numbers were correct, but the hardware would flash different (extra) numbers.
As said, first this seemed random, and I couldn't figure it out why 8 and 9 would show up on the hardware even though the dNum was set to a max of 6.
After a couple of hours I figured out that it wasn't a coding mistake as much as it was a typo.
The code in itself was okay, but I made two errors. One with eight(); and one with nine();
In both eight() and nine() the if-statement was terminated with a ;
e.g.
void loop()
{
bla bla bla
if (mapChange == 8); <-- it was this semi colon that made it ignore the if-statement
eight();
because it ignored the if-statement the eight(); and nine(); functions were run unconditionally every single time.
for further reference see
https://forum.arduino.cc/index.php?topic=54579.0
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.