so i've got a school project to do with an arduino but i dont exactly know how to make this happen:
the circuit has got 3 leds and 3 push buttons
what it will do is:
when pressed to 1st button, 1st and 3rd led will light up for a second and turn off
when pressed to 2nd button,2nd led will light up for a second and turn off for a second,when 2nd led is off,1st and 3rd led will light up
when pressed to 3rd button,1st 2nd and 3rd leds will light up by order and then turn off (1st,2nd,3rd)
LED 1 is connected to D8, LED 2 is connected to D7, LED 3 is connected to D9.
Button 1 is connected to D3, Button 2 is connected to D2, Button 3 is connected to D11.
my code (i copypasted it and tried to modify it according to what i need arduino to do thats probably where im stalled)
/* sketch 1
turn on a LED when the button is pressed
turn it off when the button is not pressed (or released)
*/
int pinButton = 3; //the pin where we connect the button
int LED = 8; //the pin we connect the LED
int LED2 = 7;
int pinButton2 = 2;
int pinButton3 = 11;
int LED3 = 9;
void setup() {
pinMode(pinButton, INPUT); //set the button pin as INPUT
pinMode(pinButton2,INPUT);
pinMode(pinButton3,INPUT);
pinMode(LED, OUTPUT); //set the LED pin as OUTPUT
pinMode(LED2,OUTPUT);
pinMode(LED3,OUTPUT);
}
void loop() {
int stateButton = digitalRead(pinButton); //read the state of the button
if(stateButton == 1) { //if is pressed
digitalWrite(LED, HIGH); //write 1 or HIGH to led pin
} else { //if not pressed
digitalWrite(LED, LOW); //write 0 or low to led pin
}
int stateButton2 = digitalRead(pinButton2); //read the state of the button
if(stateButton2 == 1) { //if is pressed
digitalWrite(LED2, HIGH); //write 1 or HIGH to led pin
} else { //if not pressed
digitalWrite(LED2, LOW); //write 0 or low to led pin
}
int stateButton3 = digitalRead(pinButton3); //read the state of the button
if(stateButton3 == 1) { //if is pressed
digitalWrite(LED3, HIGH); //write 1 or HIGH to led pin
} else { //if not pressed
digitalWrite(LED3, LOW); //write 0 or low to led pin
}
}
Thanks for taking the time to post properly, in code tags.
i copypasted it and tried to modify it according to what i need arduino to do thats probably where im stalled
Small wonder, really. That is not the way to complete a school assignment. If you were given a template to work with, that's fine. But you are supposed to make use of other course materials and supplement that with your own research, in order to gain enough understanding to finish it yourself.
Rarely is an assignment given, for which no preparation has been laid out. Did you have a good reason for skipping the lessons or classes that everyone else completed, that would give you the groundwork to confidently work on this yourself?
Also, you haven't mentioned what is wrong with your code.
HI "usernameistaken",
(well that's a funny comment about the login-process ;-))
very good posting code as a code-sesction on your very first posting.
You will finish this project with the help of this forum.
Programming is not to choose from 50 code-variants the right one and then you are finished.
I will support you and I have a request. I'm interested in what your teacher was giving you as learning ressources.
Your functional description is good. For a very first project it is a little bit ambigious.
It would be very good if you write a little bit about how much you know already about programming.
Just a rough estimation.
My understanding of this forum is to support people in learning.
Not to post ready to use code. So as a first step. Take a look into this tutorial:
It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.
pinMode(pinButton, INPUT); //set the button pin as INPUT
pinMode(pinButton2,INPUT);
pinMode(pinButton3,INPUT);
Were you not taught that a button input requires a pull-up or pull-down resistor? You don't describe any. You don't even say what the other side of the button is connected to.
aarg:
Thanks for taking the time to post properly, in code tags.
Small wonder, really. That is not the way to complete a school assignment. If you were given a template to work with, that's fine. But you are supposed to make use of other course materials and supplement that with your own research, in order to gain enough understanding to finish it yourself.
My problem was exactly just copying and pasting it directly. After surfing around net for the codes similar to what i need to do,i've figured it out.
usernameistaken:
My problem was exactly just copying and pasting it directly. After surfing around net for the codes similar to what i need to do,i've figured it out.
So does this mean you have your program up and running?
best regards Stefan