Pages: 1 [2]   Go Down
Author Topic: having a little trouble please help  (Read 1241 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

ok that works one more think though how would i get it to not bounce (go one at a time each way) ?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31555
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

No look at my reply, the bit about remembering the previous state of the button and only incrementing or decrementing when the state changes from unpressed to pressed.
To debounce just add a delay after you detect a change.
« Last Edit: August 02, 2011, 06:11:59 am by Grumpy_Mike » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

if i put a delay after the change it make the two displays kinda pulse what else can i do so it does not bounce?
thanks again for your help
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31555
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
if i put a delay after the change it make the two displays kinda pulse
Yes that is because you are not REMEMBERING the state of the buttons from one loop to the next. It is not bounce you are seeing but the fact that you have inadequacy code.
Post what you have so far.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

it does bounce though. with no delay add and with one add it pulses!

heres what i got.

Code:
int a=2;
int b=3;
int c=4;
int d=5;
int e=6;
int f=7;
int g=8;
int number=0;
int pin9=9;
int pin10=10;
int pindown=11;
int pinup=12;
int tens=0;
int unit=0;
int digit=0;
int tens1=0;
int presentvalue=0;
int previousvalue=0;


// Pins for A B C D E F G, in sequence
const int segs[7] = { 2, 3, 4, 5, 6, 7, 8, };

// Segments that make each number
const byte numbers[10] = { 0b1000000, 0b1111001, 0b0100100, 0b0110000, 0b0011001, 0b0010010,
0b0000010, 0b1111000, 0b0000000, 0b0010000 };

void setup()
{
//Serial.begin(9600);
pinMode(a,OUTPUT);
pinMode(b,OUTPUT);
pinMode(c,OUTPUT);
pinMode(d,OUTPUT);
pinMode(e,OUTPUT);
pinMode(f,OUTPUT);
pinMode(g,OUTPUT);
pinMode(pin9,OUTPUT);
pinMode(pin10,OUTPUT);
pinMode(pindown,INPUT);
pinMode(pinup,INPUT);
zero();
}

void loop()
{
presentvalue=digitalRead(pinup);
if (presentvalue!=previousvalue)
{
if (presentvalue==1)
{number=number+1;}
previousvalue=presentvalue;
}

presentvalue=digitalRead(pindown);
if (presentvalue!=previousvalue)
{
if (presentvalue==1)
{number=number-1;}
previousvalue=presentvalue;

}
display1();
}
void display1()
{
tens1=number%100;
tens=tens1/10;
unit=tens1%10;
for (int i=0;i<=10;i++)
{
 
  digit=tens;
  digitselection(); 
  digitalWrite(pin9,HIGH);
  digitalWrite(pin10,LOW);
  delay(1);
 
  digit=unit;
  digitselection(); 
  digitalWrite(pin9,LOW);
  digitalWrite(pin10,HIGH);
  delay(1);
}
if (number>99) {number=0;}
}



void zero()
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,HIGH);
}

void one()
{
digitalWrite(a,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
}

void two()
{
digitalWrite(c,HIGH);
digitalWrite(f,HIGH);
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(g,LOW);
digitalWrite(e,LOW);
digitalWrite(d,LOW);
}

void three()
{
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(g,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
}

void four()
{
digitalWrite(a,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}

void five()
{
digitalWrite(e,HIGH);
digitalWrite(b,HIGH);
digitalWrite(a,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
}

void six()
{
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
}

void seven()
{
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
}

void eight()
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}

void nine()
{
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}

void digitselection()
{
  switch (digit)
  {
    case 0:
    zero();
    break;
    case 1:
    one();
    break;
    case 2:
    two();
    break;
    case 3:
    three();
    break;
    case 4:
    four();
    break;
    case 5:
    five();
    break;
    case 6:
    six();
    break;
    case 7:
    seven();
    break;
    case 8:
    eight();
    break;
    case 9:
    nine();
    break;
  } 
}
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31555
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

This was because you were using the same previous value variable for both the up and down button. Try this:-

Code:
int a=2;
int b=3;
int c=4;
int d=5;
int e=6;
int f=7;
int g=8;
int number=0;
int pin9=9;
int pin10=10;
int pindown=11;
int pinup=12;
int tens=0;
int unit=0;
int digit=0;
int tens1=0;
int presentvalueUp=0, presentvalueDown=0 ;
int previousvalueUp=0, previousvalueDown=0;


// Pins for A B C D E F G, in sequence
const int segs[7] = { 2, 3, 4, 5, 6, 7, 8, };

// Segments that make each number
const byte numbers[10] = { 0b1000000, 0b1111001, 0b0100100, 0b0110000, 0b0011001, 0b0010010,
0b0000010, 0b1111000, 0b0000000, 0b0010000 };

void setup()
{
//Serial.begin(9600);
pinMode(a,OUTPUT);
pinMode(b,OUTPUT);
pinMode(c,OUTPUT);
pinMode(d,OUTPUT);
pinMode(e,OUTPUT);
pinMode(f,OUTPUT);
pinMode(g,OUTPUT);
pinMode(pin9,OUTPUT);
pinMode(pin10,OUTPUT);
pinMode(pindown,INPUT);
pinMode(pinup,INPUT);
zero();
}

void loop()
{
presentvalueUp=digitalRead(pinup);
if (presentvalueUp != previousvalueUp && presentvalueUp == LOW) // do it only on the falling edge of the input
{
number=number+1;
previousvalueUp=presentvalueUp;
delay(20);   // debounce delay
}

presentvalueDown=digitalRead(pindown);
if (presentvalueDown != previousvalueDown && presentvalueDown == LOW) // do it only on the falling edge of the input
{
 number=number-1;
previousvalueDown = presentvalueDown;
delay(20);   // debounce delay
}
display1();
}
void display1()
{
tens1=number%100;
tens=tens1/10;
unit=tens1%10;
for (int i=0;i<=10;i++)
{
  
  digit=tens;
  digitselection();  
  digitalWrite(pin9,HIGH);
  digitalWrite(pin10,LOW);
  delay(1);
  
  digit=unit;
  digitselection();  
  digitalWrite(pin9,LOW);
  digitalWrite(pin10,HIGH);
  delay(1);
}
if (number>99) {number=0;}
}



void zero()
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,HIGH);
}

void one()
{
digitalWrite(a,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
}

void two()
{
digitalWrite(c,HIGH);
digitalWrite(f,HIGH);
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(g,LOW);
digitalWrite(e,LOW);
digitalWrite(d,LOW);
}

void three()
{
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(g,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
}

void four()
{
digitalWrite(a,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}

void five()
{
digitalWrite(e,HIGH);
digitalWrite(b,HIGH);
digitalWrite(a,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
}

void six()
{
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
}

void seven()
{
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
}

void eight()
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}

void nine()
{
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}

void digitselection()
{
  switch (digit)
  {
    case 0:
    zero();
    break;
    case 1:
    one();
    break;
    case 2:
    two();
    break;
    case 3:
    three();
    break;
    case 4:
    four();
    break;
    case 5:
    five();
    break;
    case 6:
    six();
    break;
    case 7:
    seven();
    break;
    case 8:
    eight();
    break;
    case 9:
    nine();
    break;
  }  
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

it doesn't count when i press the button?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31555
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

How have you got the buttons wired up? Do you have a low on a press?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 514
Posts: 31555
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry try this:-

Code:
int a=2;
int b=3;
int c=4;
int d=5;
int e=6;
int f=7;
int g=8;
int number=0;
int pin9=9;
int pin10=10;
int pindown=11;
int pinup=12;
int tens=0;
int unit=0;
int digit=0;
int tens1=0;
int presentvalueUp=0, presentvalueDown=0 ;
int previousvalueUp=0, previousvalueDown=0;


// Pins for A B C D E F G, in sequence
const int segs[7] = { 2, 3, 4, 5, 6, 7, 8, };

// Segments that make each number
const byte numbers[10] = { 0b1000000, 0b1111001, 0b0100100, 0b0110000, 0b0011001, 0b0010010,
0b0000010, 0b1111000, 0b0000000, 0b0010000 };

void setup()
{
//Serial.begin(9600);
pinMode(a,OUTPUT);
pinMode(b,OUTPUT);
pinMode(c,OUTPUT);
pinMode(d,OUTPUT);
pinMode(e,OUTPUT);
pinMode(f,OUTPUT);
pinMode(g,OUTPUT);
pinMode(pin9,OUTPUT);
pinMode(pin10,OUTPUT);
pinMode(pindown,INPUT);
pinMode(pinup,INPUT);
zero();
}

void loop()
{
presentvalueUp=digitalRead(pinup);
if (presentvalueUp != previousvalueUp && presentvalueUp == LOW) // do it only on the falling edge of the input
{
number=number+1;
delay(20);   // debounce delay
}
previousvalueUp=presentvalueUp;

presentvalueDown=digitalRead(pindown);
if (presentvalueDown != previousvalueDown && presentvalueDown == LOW) // do it only on the falling edge of the input
{
 number=number-1;
delay(20);   // debounce delay
}
previousvalueDown = presentvalueDown;
display1();
}
void display1()
{
tens1=number%100;
tens=tens1/10;
unit=tens1%10;
for (int i=0;i<=10;i++)
{
 
  digit=tens;
  digitselection(); 
  digitalWrite(pin9,HIGH);
  digitalWrite(pin10,LOW);
  delay(1);
 
  digit=unit;
  digitselection(); 
  digitalWrite(pin9,LOW);
  digitalWrite(pin10,HIGH);
  delay(1);
}
if (number>99) {number=0;}
}



void zero()
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,HIGH);
}

void one()
{
digitalWrite(a,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
}

void two()
{
digitalWrite(c,HIGH);
digitalWrite(f,HIGH);
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(g,LOW);
digitalWrite(e,LOW);
digitalWrite(d,LOW);
}

void three()
{
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(g,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
}

void four()
{
digitalWrite(a,HIGH);
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}

void five()
{
digitalWrite(e,HIGH);
digitalWrite(b,HIGH);
digitalWrite(a,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
}

void six()
{
digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
}

void seven()
{
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(f,HIGH);
digitalWrite(g,HIGH);
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
}

void eight()
{
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(d,LOW);
digitalWrite(e,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}

void nine()
{
digitalWrite(d,HIGH);
digitalWrite(e,HIGH);
digitalWrite(a,LOW);
digitalWrite(b,LOW);
digitalWrite(c,LOW);
digitalWrite(f,LOW);
digitalWrite(g,LOW);
}

void digitselection()
{
  switch (digit)
  {
    case 0:
    zero();
    break;
    case 1:
    one();
    break;
    case 2:
    two();
    break;
    case 3:
    three();
    break;
    case 4:
    four();
    break;
    case 5:
    five();
    break;
    case 6:
    six();
    break;
    case 7:
    seven();
    break;
    case 8:
    eight();
    break;
    case 9:
    nine();
    break;
  } 
}
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

much better thank you so much for your help just so you know the button take a high not a low but i fixed that myself thanks again!
Logged

Pages: 1 [2]   Go Up
Jump to: