Hi, I hope someone can help me please.
Please bear with me as this is quite difficult to explain. :~
I'm making a flight simulator control panel.
I need to use toggle switches to make the panel look realistic. But the electrical output from the toggle switch is different to what I need.
When I turn on one side of the toggle switch, I need to send a short signal to another board.
Then when I turn the toggle switch off again, I need it to send the same signal again.
Is that possible?
I hope that makes sense.
Thanks in advance.
Paul
Sure - watch the switch for a change of state (lo to hi, hi to lo) and send a pulse when you see it.
Debounce the switch so you don't get multiple pulses as the switch bounces & settles.
Hi, thanks for the info.
I'm very new to all this so I did a bit of searching and I managed to cobble this together from a few different places.
/*
Multiple State Change Test
The circuit:
* Pushbuttons attached to pins 2 and 3 from +5V
* 10K resistosr attached to pins 2 and 3 from ground
* LEDs attached to pins 10 and 11 to ground
*/
const int buttonPin1 = 2; // the pin that pushbutton 1 is attached to
const int buttonPin2 = 3; // the pin that pushbutton 2 is attached to
const int ledPin1 = 10; // the pin that LED 1 is attached to
const int ledPin2 = 11; // the pin that LED 2 is attached to
// Variables will change:
int buttonState1 = 0; // current state of button 1
int buttonState2 = 0; // current state of button 2
int lastButtonState1 = 0; // previous state of button 1
int lastButtonState2 = 0; // previous state of button 2
void setup() {
// initialize the button pins as inputs
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
// initialize the LEDs as outputs
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
}
void loop() {
buttonState1 = digitalRead(buttonPin1); //Read the pushbutton input pin
// Compare the buttonState to its previous state
if (buttonState1 != lastButtonState1) { // if the state has changed,
if (buttonState1 == HIGH) { // If the button is high
digitalWrite(ledPin1, HIGH); // Turn LED 1 on
delay(250); // Wait quarter of a second
digitalWrite(ledPin1, LOW); // Turn LED 1 off
}
else { // If the button is low
digitalWrite(ledPin1, HIGH); // Turn LED 1 on
delay(250); // Wait quarter of a second
digitalWrite(ledPin1, LOW); // Turn LED 1 off
}
}
lastButtonState1 = buttonState1; // Save the current state of button 1 as the last state 1
buttonState2 = digitalRead(buttonPin2); //Read the pushbutton input pin
// Compare the buttonState to its previous state
if (buttonState2 != lastButtonState2) { // if the state has changed,
if (buttonState2 == HIGH) { // If the button is high
digitalWrite(ledPin2, HIGH); // Turn LED 2 on
delay(250); // Wait quarter of a second
digitalWrite(ledPin2, LOW); // Turn LED 2 off
}
else { // If the button is low
digitalWrite(ledPin2, HIGH); // Turn LED 2 on
delay(250); // Wait quarter of a second
digitalWrite(ledPin2, LOW); // Turn LED 2 off
}
}
lastButtonState2 = buttonState2; // Save the current state of button 2 as the last state 2
}
I put LEDs on the outputs for testing and it seems to work just how I want it to.
Thanks again for the help.
Paul
You don't need an arduino to do this you can achieve the same thing by using a circuit called a monostable. A 74LS123 has two of these circuits and costs about $0.40
Yeah, but now he can add a few more, easily change pulse widths, flash a few LEDs, add control panel display and stick shaker simulator ...
Thanks for the info Mike.
But as Crossroads eluded to, this is just the early stages of the project.
There are a lot more things I want it to do as well, a bit further down the line.
Much appreciated though.
Thanks
Paul
Hi Colaboy,
You can simplify your code like this:
// Compare the buttonState to its previous state
if (buttonState1 != lastButtonState1) { // if the state has changed,
digitalWrite(ledPin1, HIGH); // Turn LED 1 on
delay(250); // Wait quarter of a second
digitalWrite(ledPin1, LOW); // Turn LED 1 off
lastButtonState1 = buttonState1; // Save the current state of button 1 as the last state 1
}
You had something like if (X) do this, else do the same.
Regards,
Jim
Thanks for that Jim.
Being new to programing, I tend to copy and paste bits of code from different places and just try to get them to work.
I'm all for trying to do it properly though.
Thanks again.
Paul