PlatformIO package of the Teensy core framework compatible with GCC 10 & C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // Dice - Application to simulate a six sided die, using the Entropy
  2. // true random number library
  3. // The die is 7 leds wired as shown below
  4. // A B A=D7, B=D8
  5. // C D E C=D2, D=D3, E=D4
  6. // F G F=D5, G=D6
  7. #include <stdint.h>
  8. #include <Entropy.h>
  9. #include "Die.h"
  10. const int RollButton=14;
  11. const int Die1=9;
  12. const int Die2=10;
  13. Die Dice[2];
  14. byte roll[2];
  15. void setup()
  16. {
  17. Entropy.Initialize();
  18. Dice[0].Initialize(7,8,2,3,4,5,6);
  19. Dice[1].Initialize(7,8,2,3,4,5,6);
  20. pinMode(RollButton,INPUT_PULLUP);
  21. pinMode(Die1, OUTPUT);
  22. pinMode(Die2, OUTPUT);
  23. digitalWrite(Die1, LOW);
  24. digitalWrite(Die2, LOW);
  25. roll[0] = Entropy.random(1,7);
  26. roll[1] = Entropy.random(1,7);
  27. }
  28. void loop()
  29. {
  30. if (digitalRead(RollButton) == LOW)
  31. {
  32. while (digitalRead(RollButton) == LOW);
  33. roll[0] = Entropy.random(1,7);
  34. roll[1] = Entropy.random(1,7);
  35. }
  36. digitalWrite(Die1, HIGH);
  37. Dice[0].Show(roll[0]);
  38. delay(100);
  39. PORTD = 0x00;
  40. PORTB = 0x00;
  41. digitalWrite(Die2, HIGH);
  42. Dice[0].Show(roll[1]);
  43. delay(100);
  44. PORTD = 0x00;
  45. PORTB = 0x00;
  46. }