pulse nublers on arduino?

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????

sort by: active | newest | oldest
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 ?
Keyboard scanning would be more elegant if it's a set of keys/buttons, agreed.
Or a decimal-binary converter, like the 74147 ?
True. Question is, what's cheapest and/or easiest?
... which will depend in large part upon what the rest of the system is trying to do.
jcbed (author)  orksecurity5 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!!!
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...
jcbed (author)  orksecurity5 years ago
thinking this could meen a cheaper controler thats arduino code friendley eg at tiney could be used
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;

While true //Loops infinitely
//Read a byte (Sw_number) from the switch input.
//Messy code
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;
} //End if
} //End while - Now go to beginning.

This will only pulse the outputs when the input changes.
Ooops, various issues with letter case here - I usually write in a language that doesn't care
jcbed (author)  steveastrouk5 years ago
thgancks soo much