Go Down

Topic: Need Help with Bounce Library ver1.1 (Read 360 times) previous topic - next topic

Lazer57

Sep 07, 2009, 05:07 pm Last Edit: Sep 07, 2009, 05:16 pm by Lazer57 Reason: 1
Relevant code at bottom(reversed order):

I downloaded the new version and this one actually lets the code compile. I think I followed the instructions correctly judging by the example and I have looked it over many times and I don't see what I have done wrong. Any help would be great as it is crucial for this project. I have tried many different time values for bounce (from 5millis to 2 seconds, no difference).

Code chunk 2 (time setting while block):
Quote

    // CHANGES THE DEFAULT GAME TIME
    while(dip1==1){
      dip1 = digitalRead(timePin);    // read the input pin for dipswitch 1
      button1 = digitalRead(butt1Pin);   // read the input pin for button 1
      button2 = digitalRead(butt2Pin);  // read the input pin for button 2
      
      setTime1.update();        // updating bounce object for buttons 1 and 2
      setTime2.update();        // MOVE DIGIT is button 1, SET DIGIT is button 2
      int time1Val = setTime1.read();
      int time2Val = setTime2.read();
      
      if(time1Val==HIGH){
        Serial.println("BUTTON 1");
        Serial.println(time1Val);
      }
      if(time2Val==HIGH){
        Serial.println("BUTTON 2");
        Serial.println(time2Val);
      }
      
      if(dip1==0){
      disp1Metro.reset();
      disp2Metro.reset();
      }
      
      if(time1Val==HIGH){
        setDigit += 1;
        if(setDigit >= 4){
          setDigit = 0;
        }
      }
      
      switch(setDigit){
        case 0:
          d2 = 0x78;
          c2 = c;
          b2 = b;
          a2 = a;
          if(time2Val==HIGH){
            d += 1;
            if(d >= 10){
              d = 0;
            }
          }
          break;
          
        case 1:
          d2 = d;
          c2 = 0x78;
          b2 = b;
          a2 = a;
          if(time2Val==HIGH){
            c += 1;
            if(c >= 10){
              c = 0;
            }
          }
          break;
        
        case 2:
          d2 = d;
          c2 = c;
          b2 = 0x78;
          a2 = a;
          if(time2Val==HIGH){
            b += 1;
            if(b >= 10){
              b = 0;
            }
          }
          break;
        
        case 3:
          d2 = d;
          c2 = c;
          b2 = b;
          a2 = 0x78;
          if(time2Val==HIGH){
            a += 1;
            if(a >= 10){
              a = 0;
            }
          }
          break;  
      }
      
      if(blinkMetro.check() == 1){
        blinkMetro.reset();
        shiftOut(dataPin, clockPin, MSBFIRST, d2);
        shiftOut(dataPin, clockPin, MSBFIRST, c2);
        shiftOut(dataPin, clockPin, MSBFIRST, b2);
        shiftOut(dataPin, clockPin, MSBFIRST, a2);
        timeDelay = millis();
      }
      if(millis() - timeDelay >= 100){
        shiftOut(dataPin, clockPin, MSBFIRST, d);
        shiftOut(dataPin, clockPin, MSBFIRST, c);
        shiftOut(dataPin, clockPin, MSBFIRST, b);
        shiftOut(dataPin, clockPin, MSBFIRST, a);
      }
    }



Code chunk 1 (variables, buttons, etc):
Code: [Select]
#include <Bounce.h>
#include <Metro.h>


Metro disp1Metro = Metro(1000);
Metro disp2Metro = Metro(1000);
Metro blinkMetro = Metro(750);
long timeDelay = 0;      // variable used to hold millis() for display blinking
int dataPin = 2;                   // connect to MOSI on both displays
int clockPin =3;                   // connect to SCK on both displays
int CS1 = 4;                       // connect to CS on first display
int CS2 = 5;                       // connect to CS on second display
int butt1Pin = 7;                 // input pin for button 1
int butt2Pin = 8;                 // input pin for button 2
int button1 = 0;                   // variable to store the read value of button1
int button2 = 0;                   // variable to store the read value of button2
int dip1 = 0;                      // variable to store the read value of dipswitch1
int hold = 0;                    // holds button value
int pause = 0;                    // variable to store the read value of pause latching switch
int a = 0;      // seconds variable
int b = 0;      // tens of seconds variable
int c = 1;      // minutes variable
int d = 0;      // tens of minutes variable
int b1Array[4] = {d, c, b, a};      //number2 to be displayed on CS1
int b2Array[4] = {d, c, b, a};      //numbers to be displayed on CS2
int alarmPin = 10;                  //triggers piezo buzzer
int timePin = 12;                   // switch to set time
int pausePin = 11;                  // pauses clock
Bounce setTime1 = Bounce(butt1Pin, 100);    // instantiate bounce object for button 1
Bounce setTime2 = Bounce(butt2Pin, 100);    // instantiate bounce object for button 2
int a2 = a;      // variables used for changing default time
int b2 = b;
int c2 = c;
int d2 = d;
int setDigit = 0;    // variable for selecting what time digit to blink and thus change

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy