Go Down

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

#### Lazer57

##### Sep 07, 2009, 05:07 pmLast 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){

setTime1.update();        // updating bounce object for buttons 1 and 2
setTime2.update();        // MOVE DIGIT is button 1, SET DIGIT is button 2

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;
}

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 blinkingint dataPin = 2;                   // connect to MOSI on both displaysint clockPin =3;                   // connect to SCK on both displaysint CS1 = 4;                       // connect to CS on first displayint CS2 = 5;                       // connect to CS on second displayint butt1Pin = 7;                 // input pin for button 1int butt2Pin = 8;                 // input pin for button 2int button1 = 0;                   // variable to store the read value of button1int button2 = 0;                   // variable to store the read value of button2int dip1 = 0;                      // variable to store the read value of dipswitch1int hold = 0;                    // holds button valueint pause = 0;                    // variable to store the read value of pause latching switchint a = 0;      // seconds variableint b = 0;      // tens of seconds variableint c = 1;      // minutes variableint d = 0;      // tens of minutes variableint b1Array[4] = {d, c, b, a};      //number2 to be displayed on CS1int b2Array[4] = {d, c, b, a};      //numbers to be displayed on CS2int alarmPin = 10;                  //triggers piezo buzzerint timePin = 12;                   // switch to set timeint pausePin = 11;                  // pauses clockBounce setTime1 = Bounce(butt1Pin, 100);    // instantiate bounce object for button 1Bounce setTime2 = Bounce(butt2Pin, 100);    // instantiate bounce object for button 2int a2 = a;      // variables used for changing default timeint b2 = b;int c2 = c;int d2 = d;int setDigit = 0;    // variable for selecting what time digit to blink and thus change`

Go Up