I wanna make a simple design with two Toggle switches ON-ON and green LED.
Currently the toggle switch is connected to a 64 BBI leobodnar joystick board and mapped in DCS flight sim.
And i wanna add a LED, that turns green after 13 secs after i flipped the switch nr 1 up.
Then i wanna set a timer to turn the LED off (after 1.5min) after i toggle switch nr 2
Any good ideas how to do this?
Does the toggle switch have a mechanically tied but electrically separate pole? If so, take one "throw" of the second pole, not tied to the flight simulator into an output pin on the Arduino. I am assuming you are here on this forum because you are wanting to involve Arduino programming. The second "throw, into a separate output pin. The actuator of that pole into an input pin on the Arduino. In your program, set output 1 HIGH and output 2 LOW. Then use digitalRead() on the actuator input pin to determine if you are high or low and toggle the LED output pin accordingly, with a millis() function to track the 13 second delay. If there is not a second pole, replace the toggle switch with a DPDT On-On switch.
Thank u for the Quick response, im trying to learn arduino so its kinda fresh =) But i kinda understand what u mean.
I found this code, and when i hook the first switch and one led it works IF its a temporary switch not ON-ON DTSP like im using now. If i just toggle the switch this works and he counts 3seks and then goes out.
Now im trying to figure out the following.
- How do i get the led to count the 3secs even if the toggle switch is ON at the whole time?
- And also, how could the code look for the second switch when i wanna turn if off after 1.5min?
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(){
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH)
{
digitalWrite(ledPin, HIGH);
delay (3000);
digitalWrite(ledPin, LOW);
}
if (buttonState == LOW)
{
digitalWrite(ledPin, LOW);
}
}
Japmaco:
I found this code,
This makes my non-existent hair stand on end. When you open Arduino for the first time, there is a void setup() and a void loop(). It is much easier to go from there to where you want to be, than to doctor code written by someone else for something else. Go back to that blank canvas. Forget the programming language for now. write in your own words things you know you need to do once and things you know you want to do over and over. for example:
void setup() {
// put your setup code here, to run once:
//setup pins
}
void loop() {
// put your main code here, to run repeatedly:
//read inputs
//turn on/off led
}
You want to know every word in your program, why it's there, what it does, and how it works. Only add what you have learned. Starting with what I've typed above, there are already words you might have questions about. "setup()" and "loop()" are both functions that are called from within the Arduino core. The word "void" means they will not return a value to the command that called them. setup is called once by the core, and loop is repeatedly called forever after, each time loop completes and returns, the Arduino core calls it again. Once you have written what you want to do in your own words, in small steps, you have laid out the structure of your program and can begin to ask questions and learn how to code each step.