Advertisement
notalentgeek

Arduino - Serial.println() Weird Problem

Jul 15th, 2015
288
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.81 KB | None | 0 0
  1. #define PIN_DICE        A5
  2. #define PIN_RANDOM_SEED A0
  3.  
  4. int     numberDice                  = 0;
  5. bool    numberDiceNew               = false;
  6. int     counterDice                 = 0;
  7. int     counterDiceThreshold        = 10;
  8. bool    counterInitialTrigger       = false;
  9. int     counterInitialDuration      = 1000;
  10. int     counterInitialDurationMax   = 1000;
  11. int     statePin                    = 0;
  12. int     statePinPrevious            = 0;
  13.  
  14. void setup(){
  15.     Serial.begin    (9600);
  16.     pinMode         (A5, INPUT);
  17. }
  18.  
  19. void loop(){
  20.     //POINT OF INTEREST 1.
  21.     Serial.println("PUT ANY STRING HERE!");
  22.     randomSeed(analogRead(PIN_RANDOM_SEED));
  23.     int analogPinValue              = analogRead(PIN_DICE);
  24.     if(analogPinValue               > 511)          { statePin = 1; }
  25.     else if(analogPinValue          <= 511)         { statePin = 0; }
  26.     if(statePinPrevious             != statePin)    { counterInitialTrigger = true; }
  27.     if(counterInitialTrigger){
  28.         if(statePinPrevious         != statePin)    { counterDice ++; }
  29.         counterInitialDuration      --;
  30.     }
  31.     if(counterDice                  >= counterDiceThreshold){
  32.         numberDice                  = random(1, 21);
  33.         numberDiceNew               = true;
  34.         counterDice                 = 0;
  35.         counterInitialDuration      = counterInitialDurationMax;
  36.         counterInitialTrigger       = false;
  37.     }
  38.     if(counterInitialDuration       <= 0){
  39.         counterDice                 = 0;
  40.         counterInitialDuration      = counterInitialDurationMax;
  41.         counterInitialTrigger       = false;
  42.     }
  43.     statePinPrevious                = statePin;
  44.     if(numberDiceNew){
  45.         //POINT OF INTEREST 2.
  46.         Serial.println              (numberDice);
  47.         numberDiceNew               = false;
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement