125Views11Replies

Author Options:

pulse nublers on arduino? Answered

hpw would you use an arduino to read a number from 1-10 (read which is high) on 10 pins then when another pin is high do the relevent humber of pulsces on another pin????

Discussions

The forums are retiring in 2021 and are now closed for new topics and comments.
0
steveastrouk
steveastrouk

9 years ago

I woudn't use 10 pins for the input if I could help it. Will you be pressing a key or something to give it the number ?

0
orksecurity
orksecurity

Answer 9 years ago

Keyboard scanning would be more elegant if it's a set of keys/buttons, agreed.

0
steveastrouk
steveastrouk

Answer 9 years ago

Or a decimal-binary converter, like the 74147 ?

0
orksecurity
orksecurity

Answer 9 years ago

True. Question is, what's cheapest and/or easiest?

0
orksecurity
orksecurity

Answer 9 years ago

... which will depend in large part upon what the rest of the system is trying to do.

0
jcbed
jcbed

Answer 9 years ago

i was planning to use a rotary swtich as the input as theyre fairely robust and they can be mounted through a hole as the planned use is in a milking parluer to giv the cows a sertian portian of cake and thanks to thoes who have replied alredy it's suprised me!!!

0
orksecurity
orksecurity

Answer 9 years ago

If you're going with a rotary switch... you could also use one of the Arduino's analog inputs with a resistor ladder to give the positions different resistances.

When dealing with computers, even small ones, there are usually multiple reasonable solution...

0
jcbed
jcbed

Answer 9 years ago

thinking this could meen a cheaper controler thats arduino code friendley eg at tiney could be used

0
steveastrouk
steveastrouk

9 years ago

If you're using a rotary switch, you definitely want to go with the 74147 route. It will save a lot of pins, and probably be more reliable than using up 10 pins - you'll need only 4 this way.

The rest is simple code too, basically - kind of like this.


sw_number = 0;
old_number=0;

While true //Loops infinitely
{
//Read a byte (Sw_number) from the switch input.
//Messy code
Sw_number=DigitalRead(pin1);
Sw_number=sw_number <<1 +DigitalRead(pin2);
Sw_number:=sw_number << 1 +digitalRead(pin3);
Sw_number:=sw_number << 1 +digitalRead(Pin4);

If old_number <> Sw_number
{

//Now, for whatever count it registers, pulse output count times.
For (int ctr = 0; x < Sw_number, x++)
{pulse_pin = true;
delay(10);
pulse_pin:=false;
}
old_number:=Sw_number;
} //End if
} //End while - Now go to beginning.


This will only pulse the outputs when the input changes.

0
steveastrouk
steveastrouk

Answer 9 years ago

Ooops, various issues with letter case here - I usually write in a language that doesn't care

0
jcbed
jcbed

Answer 9 years ago

thgancks soo much