Go Down

Topic: Problem with counter (Read 1 time) previous topic - next topic

arduino2141991

Jun 09, 2016, 10:54 am Last Edit: Jun 09, 2016, 11:52 am by arduino2141991
Hello guys, I have a problem about programming several counters in the same arduino UNO.
Previously I set up one counter and everything was OK, it worked ( the led brights) but when I add a second counter, it doesn't count.

The setting works this way : When I push the button (P1-P2) its corresponding LED brights. P1 for M1 and P2 for M2. But when I add the second counter, both buttons activate the same LED (M1) and M2 stay off. Any ideas?? Thanks for reading.


I show you the code:

int P1 = 3;             // first push button pin
int M1 = 8;             // first engine pin
int contaA = 0;         //first counter (P1 counter)

int P2 = 4;             // second push button pin
int M2 = 9;             // second engine pin
int contaB = 0;         // second counter (P2 counter)



     
void setup()

{
  Serial.begin(9600);
  pinMode(P1, INPUT);       
  pinMode(M1, OUTPUT);     
  pinMode(P2, INPUT);       
  pinMode(M2, OUTPUT);     

}


void loop()

{
 
 if (digitalRead(P1)==HIGH)
  {
   delay(100);
   if (digitalRead(P1)==LOW)
    {
      contaA++;             
      Serial.println(contaA);
      delay(500);
    }
  }
 if (contaA==1)
 {
  digitalWrite(M1, HIGH);
 }
 if (contaA==2)
 {
  digitalWrite(M1, LOW);
  contaA=0;
 }


 if (digitalRead(P2)==HIGH)
  {
    delay(100);
    if (digitalRead(P2)==LOW)
    {
      contaB++;           
      Serial.println(contaB);
      delay(500);
    }
  }
  if (contaB==1)
 {
  digitalWrite(M2, HIGH);
 }
  if (contaB==2)
 {
  digitalWrite(M2, LOW);
  contaB=0;
 }

 
 
}

TomGeorge

#1
Jun 09, 2016, 11:34 am Last Edit: Jun 09, 2016, 11:35 am by TomGeorge
Hi,

Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

How have you got your buttons wired and have your LEDs got current limit resistors?

Tom... :)

Everything runs on smoke, let the smoke out, it stops running....

PaulS

Code: [Select]
int contaA = 0;         // first push button pin
Does that comment really mean anything?

How does it distinguish that variable from P1 which has the SAME comment?

How are the buttons sewn on? In other words, how are the switches wired? I'm guessing that "not correctly" is the answer, and that, therefore, you have a floating pin (or two), which gives unpredictable results.

arduino2141991

That comment was a mistake, it's correct now. Sorry

The switches and leds are wired correctly, i'm an electronic.

My doubt is about programing arduino. Can there be 2 different counter? Like conta1 and conta2. Because the circuit works but only one led is working and it works with both of the push buttons.

Thank for your reply.

PaulS

Quote
The switches and leds are wired correctly, i'm an electronic.
An electronic what? Letter opener? Stapler?

You may be an expert in some aspect of electronics, but, if you were, I think you'd KNOW that the schematic is what matters. So, where the f**k is yours?

TomGeorge

Hi,

Do you have pullup or pulldown resistors on the arduino inputs that are connected to the buttons?

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks..  Tom.. :)
Everything runs on smoke, let the smoke out, it stops running....

arduino2141991

An electronic what? Letter opener? Stapler?

You may be an expert in some aspect of electronics, but, if you were, I think you'd KNOW that the schematic is what matters. So, where the f**k is yours?
Man, calm down please, I didn't offend you bro. If you are a fascist it's Ok for you but not for me.
If you count till 1500 you will see you are a neurotic person with serious mental problems.

Don't be proud of you, you're nothing comparing with me.

Bless you.

arduino2141991

The circuit is not the matter here, it's correctly. To let you know, there is no need to use a protoboard and schematic always, it's just for noobs. The wires are in the air, also I don't need a push button, I use a resistor directly connected to the pin and the led are the same way.

Just to let you know, everything is working now and not thanks to you.

The master Tino was my teacher.

Get my bless and go to hell.

AWOL

#8
Jun 09, 2016, 12:30 pm Last Edit: Jun 09, 2016, 12:50 pm by AWOL
. . . .and with that, we say a temporary goodbye to @arduino2141991, who can, perhaps, employ the timeout to learn about code tags, how not to use delay, and netiquette.

TomGeorge

Hi..
Quote
To let you know, there is no need to use a protoboard and schematic always, it's just for noobs. 
ohhhh and he wanted us to help him? ? ?

I was nice, congenial, asked for the basic information??
(I recon he didn't have pullup or down resistors...)

Tom..... :)
Everything runs on smoke, let the smoke out, it stops running....

PaulS

Quote
I recon he didn't have pullup or down resistors...
I think you misspelled clue. 8)

TomGeorge

Everything runs on smoke, let the smoke out, it stops running....

Go Up