Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define PIN_DICE A5
- #define PIN_RANDOM_SEED A0
- int numberDice = 0;
- bool numberDiceNew = false;
- int counterDice = 0;
- int counterDiceThreshold = 10;
- bool counterInitialTrigger = false;
- int counterInitialDuration = 1000;
- int counterInitialDurationMax = 1000;
- int statePin = 0;
- int statePinPrevious = 0;
- void setup(){
- Serial.begin (9600);
- pinMode (A5, INPUT);
- }
- void loop(){
- //POINT OF INTEREST 1.
- Serial.println("PUT ANY STRING HERE!");
- randomSeed(analogRead(PIN_RANDOM_SEED));
- int analogPinValue = analogRead(PIN_DICE);
- if(analogPinValue > 511) { statePin = 1; }
- else if(analogPinValue <= 511) { statePin = 0; }
- if(statePinPrevious != statePin) { counterInitialTrigger = true; }
- if(counterInitialTrigger){
- if(statePinPrevious != statePin) { counterDice ++; }
- counterInitialDuration --;
- }
- if(counterDice >= counterDiceThreshold){
- numberDice = random(1, 21);
- numberDiceNew = true;
- counterDice = 0;
- counterInitialDuration = counterInitialDurationMax;
- counterInitialTrigger = false;
- }
- if(counterInitialDuration <= 0){
- counterDice = 0;
- counterInitialDuration = counterInitialDurationMax;
- counterInitialTrigger = false;
- }
- statePinPrevious = statePin;
- if(numberDiceNew){
- //POINT OF INTEREST 2.
- Serial.println (numberDice);
- numberDiceNew = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement