hi all! small help

This is what i want to do:
(A).Take one pulsh on pin2 turns ledPin HIGH.If takes five pulsh on pins4 turn ledPin LOW.
(B).Take two pulsh on pin2 turns ledPin HIGH.If takes ten pulsh on pins4 turn ledPin LOW.
(C).Take four pulsh on pin2 turns ledPin HIGH.If takes twenty pulsh on pins4 turn ledPin LOW.
(D).....
(E).... go on.

My problem is:

(i use button to tested)

When i pressing buttonPin(pin2) one time turns ledPin HIGH and if i press buttonPinb(pin4) five times turn ledPin LOW.so far so good.
When i pressing buttonPin(pin2) two times turns ledPin HIGH and if i press buttonPinb(pin4) five times turn ledPin LOW.(not ten).
The same happens in all situations.The ledPin turn LOW with five pulsh. No matter how many times I pressed the buttonPin(2).
Thanks to all!

This is what i have done in sketch:

const int buttonPin = 2;
const int buttonPinb = 4;
const int ledPin = 13;

int buttonPushCounter = 0;
int buttonPushCounterb = 0;
int buttonState = 0;
int buttonStateb = 0;
int lastButtonState = 0;
int lastButtonStateb = 0;

void setup() {
pinMode(buttonPin, INPUT);
pinMode(buttonPinb, INPUT);
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}

void loop() {
buttonState = digitalRead(buttonPin);
buttonStateb = digitalRead(buttonPinb);
if (buttonState != lastButtonState) {
if (buttonState == HIGH)
buttonPushCounter++;
lastButtonState = buttonState;
buttonPushCounterb = 0;
if (buttonPushCounter % 4 == 1){
digitalWrite(ledPin, HIGH);
}else if (buttonPushCounter % 4 == 2){
digitalWrite(ledPin, HIGH);
}
}
if (buttonStateb != lastButtonStateb){
if (buttonStateb == HIGH)
buttonPushCounterb++;
lastButtonStateb = buttonStateb;
buttonPushCounter = 0;
if (buttonPushCounter % 1 == 0){
if (buttonPushCounterb % 5 == 0){
digitalWrite(ledPin, LOW);
}
if (buttonPushCounter % 2 == 0){
if (buttonPushCounterb % 10 == 0){
digitalWrite(ledPin, LOW);
}

}

}

}
}

const int  buttonPin = 2;
const int  buttonPinb = 4;
const int ledPin = 13;

int buttonPushCounter = 0;
int buttonPushCounterb = 0;
int buttonState = 0;
int buttonStateb = 0;
int lastButtonState = 0;
int lastButtonStateb = 0;

void setup() {
	pinMode(buttonPin, INPUT);
	pinMode(buttonPinb, INPUT);
	pinMode(ledPin, OUTPUT);
	Serial.begin(9600);
}


void loop() 
    {
    buttonState = digitalRead(buttonPin);
    buttonStateb = digitalRead(buttonPinb);

    if (buttonState != lastButtonState) 
        {
	if (buttonState == HIGH)
		buttonPushCounterb += 5;  // Add 5 to the pushes needed to turn off LED
	 lastButtonState = buttonState;
         }


    if (buttonStateb != lastButtonStateb)
        {
	if (buttonStateb == HIGH)
            {
            if (buttonPushCounterb > 0)
                buttonPushCounterb--;  // Subtract 1 from the pushes needed to turn off LED
            }
	lastButtonStateb = buttonStateb;
        }

    if (buttonPushCounterb > 0)
         digitalWrtite(ledpin, HIGH);
    else
         digitalWrite(ledpin, LOW);
    }

I'm confused I do not know how to unite the statements (A) (B) (C) in a program.

Your question needs a little more explanation.

I'm looking to find a way that I have all 3 situations(A B C) in the program.
If i give 1 pulse to pin2 do the ledPin HIGH and if i give 5 pulse to pin4 do the ledPin LOW,
if i give 2 pulse to pin2 do the ledPin HIGH and if i give 10 pulse to pin4 do the ledPin LOW
and finaly if i give 4 pulse to pin2 do the ledPin HIGH and if i give 20 pulse to pin4 do the ledPin LOW.

I want to make a program that when given a pulse(if one pulse do ledPin HIGH) wait to get five pules(if five pulse do ledPin LOW) and when given two pulses (if two pulse do ledPin HIGH) wait to get ten pulse(if ten pulse do the ledPin LOW) and when give four pulses(if four pulse do ledPin HIGH) wait to get twenty pulse(if twenty pulse do the ledPin LOW). :blush:

Yes yes yes!!!!! 1on=5off, 2on=10off, 4on=20off in different pins (1,2,4, on pin2) and (5,10,20 on pin4)
I have a bill acceptor when takes 5 euro bill gives 1 pulse,when takes 10 euro bill gives 2 pulse and when takes 20 euro bill gives 4 pulse.
the pulse time is 50ms per pulse.
And a have a hopper(coin counter machine) when hopper is on, extract and counting the coins (5-7 coins per sec).?ach coin is 1 pulse.

Thanks all for the response!

The hopper is counting coins.How counting coins: when extract 1 coin gives 1 pulse when extract 2 coins gives 2 pulse etc.

when you take 5 euro(1 pulse on pin2)turn hopper on, and wait the hopper to gives you 5 pulse on pin4(5 coins of 1 euro)then turn hopper off, if you take 10 euro(2 pulse on pin2)turn hopper on, and wait the hopper to gives you 10 pulse on pin4(10 coins of 1 euro)then turn hopper off and if you take 20 euro(4 pulse on pin2)turn hopper on, and wait the hopper to gives you 20 pulse on pin4(20 coins of 1 euro)then turn hopper off.

He wants to dispense 1 euro coins when someone puts in 5, 10, or 20 euro bills.

For each 5 euro of bill value the bill detector sends a pulse: 1 for a 5 euro note, 2 for a 10 euro note and 4 for a 20 euro note.

For each pulse of the input he wants the coin dispenser to dispense five coins. Each time it dispenses a coin it produces one pulse. When done dispensing he turns the dispenser (represented by the LED) off.

So far he has not commented on the code I provided to do exactly that. :frowning:

Mr. johnwasser your program works perfectly, but I try to add the action for other banknotes and coins but i can not find the way.
I dont speek good english,but i'm trying. :slight_smile:

Hi Lefteris_OK

What is the nautre of the pulses on your machines? Is it a 5V change in voltage, is it like a switch that closes or open, or what?

I would have made the code like this:

  1. Check billButton. If pulse: count 1up on billNumber.
  2. Check coinButton. If pulse: count 1up on coinNumber.
  3. If billNumber >0: Start LED.
  4. If coinNumber >= 5*billNumber: stop LED, set billNumber to 0, set coinNumber to 0.

Is this homework or a real application?

-Fletcher

5x
OUTPUT from hopper and INPUT to the arduino
the pulse is 5,10,20
if take 5 led off
if take 10 led off
if take 20 led off

bill acceptor
OUTPUT from the bill acceptor and INPUT to the arduino
the value is 1,2,4
if take 1 led on
if take 2 led on
if take 4 led on

KE7GKP:
Still not clear to me whether the 5x coin count is an INPUT (as implied in the question) or an OUTPUT. Perhaps that is why I am confused. I would think that a change machine would take in paper currency (counted by the pulses from the bill acceptor) and then OUTPUT pulses to the coin dispenser.

My understanding is that the coin dispenser has an on/off input (represented by the LED) and a pulse output which signals that a coin has been dispensed (represented by the second button). The program turns on the coin dispenser until the right number of coins have been dispensed and then turns off the coin dispenser.

Lefteris_OK:
I do tha but the led is not turn off when i pressed the button(pin)4

You changed the program I gave you and made it stop working. Perhaps you should not have done that.

You 're right program is very good.You have my word will not hurt your program again!!!
Thank you all very much.Mr johnwasser you help me!Thanks :slight_smile: