Offline
Jr. Member
Karma: 0
Posts: 59
|
 |
« on: January 27, 2011, 12:11:24 pm » |
Switch in the on position->led lights up for 5 seconds and off again untill switch reset? Is there any way i can get my arduino to run like this?
|
|
|
|
|
Logged
|
|
|
|
|
Copenhagen, Denmark
Offline
God Member
Karma: 18
Posts: 838
Have you testrun your PDE file today?
|
 |
« Reply #1 on: January 27, 2011, 12:18:22 pm » |
Yes very easily:
In the loop examine the switch input pin. if HIGH and FLAG is LOW turn on the LED; wait 5 secs; turn LED off; set FLAG HIGH if LOW and FLAG is HIGH Set FLAG LOW
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 59
|
 |
« Reply #2 on: January 27, 2011, 12:24:14 pm » |
Thanks for the reply. Im totally new to all this. Ermm do you recon you can get a little more detailed with that? Absolute beginners talk? Much appreciated. Samuel
|
|
|
|
|
Logged
|
|
|
|
|
Copenhagen, Denmark
Offline
God Member
Karma: 18
Posts: 838
Have you testrun your PDE file today?
|
 |
« Reply #3 on: January 27, 2011, 12:34:19 pm » |
Yes.... in effect writing the program. It will be the same lines just with correct syntax. For this look at the http://arduino.cc/en/Reference/HomePage page and click on if() to get syntax details. Remember the two '=' inside the if - a common beginner fault. A nearly complete example close to what you need is the http://arduino.cc/en/Tutorial/ButtonExamine this, include/modify what I suggest, and see if you can work it out. Good luck/work!
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 59
|
 |
« Reply #4 on: January 27, 2011, 01:24:14 pm » |
Thanks for the point in the right direction but im still totally stumpped.. Im waiting for my arduino to turn up in the post. So im trying to crack this code thing before it comes. Any more help possible?
|
|
|
|
|
Logged
|
|
|
|
|
Copenhagen, Denmark
Offline
God Member
Karma: 18
Posts: 838
Have you testrun your PDE file today?
|
 |
« Reply #5 on: January 27, 2011, 01:59:37 pm » |
Help to self-help  Download the Arduino software, and write your code. USe the Arrow-button (or Ctrl-R) to compile. You can do this without the arduino board. When you have written what you hope is the right code and it compiles without errors, then post it here, and I'll gladly comment on it.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 59
|
 |
« Reply #6 on: January 29, 2011, 01:39:03 pm » |
Hi, This is what i got so far but no luck...
const int buttonPin = 2; // the number of the pushbutton pin const int ledPin = 13; // the number of the LED pin
// variables will change: int buttonState = 0; // variable for reading the pushbutton status
void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); }
void loop(){ // read the state of the pushbutton value: buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState == HIGH) { // turn LED on: digitalWrite(ledPin, HIGH); delay(5000); digitalWrite(ledPin, LOW); } else { // turn LED off: digitalWrite(ledPin, LOW); } }
Suggestions? Thanks
|
|
|
|
« Last Edit: January 29, 2011, 10:44:28 pm by swifftyb »
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 313
Posts: 35507
Seattle, WA USA
|
 |
« Reply #7 on: January 29, 2011, 08:35:48 pm » |
At the end of the delay, it might help if you turned the LED off. It doesn't go off on it's own.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Jr. Member
Karma: 0
Posts: 59
|
 |
« Reply #8 on: January 30, 2011, 05:15:43 am » |
I changed that but for some reason it still wont work... hmm
|
|
|
|
|
Logged
|
|
|
|
|
Copenhagen, Denmark
Offline
God Member
Karma: 18
Posts: 838
Have you testrun your PDE file today?
|
 |
« Reply #9 on: January 30, 2011, 05:38:43 pm » |
"Does not work" is not enough a description. What is happening, and what are you expecting to happen?
You left out the code with the FLAG variable from my earlier suggestions. It ensured you also have to release the button/toggle the switch back. Your code will leave the LED on for as long as the switch is on.
|
|
|
|
|
Logged
|
|
|
|
|
|