hello,
i have to read 4 pushbuttons via pin 2,3,4,5
give led output to pin 6,7,8,9
when button 2 is high led at 6 will glow and simultaneously if button pin 3 is high led at 7 will glow and
so on
right_arm.ino (772 Bytes)
hello,
i have to read 4 pushbuttons via pin 2,3,4,5
give led output to pin 6,7,8,9
when button 2 is high led at 6 will glow and simultaneously if button pin 3 is high led at 7 will glow and
so on
right_arm.ino (772 Bytes)
What's not working?
.
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.
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?
Thanks we need to see how you have connected everything.. Tom..
First, welcome to the Forum. The post titled How To Use This Forum at the top of the Forum by Nick Gammon will help you get a better response to your questions if you follow his guidelines, especially about posting your source code. A lot of us are a little gun-shy about opening files with unknown content. Use code tags and post the source code.
Second, use Ctrl-T in the IDE to reformat your program into a common C style that's easier for us to read.
Finally, you can simplify your code a lot by learning about arrays. Arrays allow you to use a single variable name to reference numerous elements of that array.
sarveshpatil:
hello,i have to read 4 pushbuttons via pin 2,3,4,5
give led output to pin 6,7,8,9
when button 2 is high led at 6 will glow and simultaneously if button pin 3 is high led at 7 will glow and
so on
I couldn’t find anything wrong with your code (Nice Job) I had fun considering how to simplify it and I came up with this:
int pbr[4] = {2,3,4,5};
int sr[4] = {6,7,8,9};
void setup() {
for(int x = 0; x<4; x++){
pinMode(pbr[x], INPUT);
pinMode(sr[x], OUTPUT);
}
}
void loop() {
for(int x = 0; x<4; x++){
digitalWrite(sr[x],(digitalRead(pbr[x]) == HIGH) ? HIGH : LOW); // this could be simplified to: digitalWrite(sr[x],digitalRead(pbr[x]);
}
}
Z
Hi,
By the looks of your code you are using your buttons to pull the input pin HIGH, do you have a 10k resistor on each of those pins to gnd so that when you release the button the input pin will be pulled to gnd (LOW).
Tom…
thanks guys
really appreciate
tested again, it work's
thanks zhomeslice !!!
had a faulty power source
thanks for everything!!!!