Results 11 to 17 of 17
Thread: Turning switches off
-
10-20-2013, 06:04 AM #11
- Join Date
- Sep 2013
- Location
- Cornwall, UK
- Posts
- 42
Re: Turning switches off
Hi!
Sorry to keep asking so many questions - I'm an arduino noob
I tried what you suggested but the serial monitor still shows that it is sending repeated C02/C01 lines.
int val = 0;int inputPin = 2;
int valOld = 0;
void setup()
{
pinMode(inputPin, INPUT);
Serial.begin(9600);
digitalWrite(inputPin, HIGH);
}
void loop() {
val = digitalRead(inputPin);
if (val != valOld); {
if (val == HIGH) { Serial.println("C02"); } else { Serial.println("C01"); };
valOld = val;
}
}
-
10-20-2013, 09:47 AM #12
- Join Date
- Apr 2011
- Location
- United States of America
- Posts
- 233
Re: Turning switches off
That's ok. I encourage it because we all had to start somewhere.
Usually when I have difficulty, I serialPrint the variables for troubleshooting; similar to how you are using C01/C02.
Serial.println("val");
Serial.println("valOld")
delay(750);
-
10-20-2013, 11:49 AM #13
- Join Date
- Sep 2013
- Location
- Cornwall, UK
- Posts
- 42
Re: Turning switches off
I did it!
For some reason it wouldn't work as just an 'if' statement so I changed it to an 'if{}else' statement and it worked.
For anybody that may be experiencing similar problems:
int val = 0;int inputPin = 2;
int valOld = 0;
void setup()
{
pinMode(inputPin, INPUT);
Serial.begin(9600);
digitalWrite(inputPin, HIGH);
}
void loop() {
val = digitalRead(inputPin);
if (val == valOld) {
} else {
if (val == HIGH) { Serial.println("C02"); } else { Serial.println("C01"); };
valOld = val;
}
delay(500);
}
Last edited by samfranklin; 10-20-2013 at 11:52 AM. Reason: Edit in coding
-
10-20-2013, 12:28 PM #14
- Join Date
- Apr 2011
- Location
- United States of America
- Posts
- 233
Re: Turning switches off
Awesome. It is strange you had to use an else statement to make it work.
Code:int val = 0;int inputPin = 2; int valOld = 0; void setup() { pinMode(inputPin, INPUT); Serial.begin(9600); digitalWrite(inputPin, HIGH); } void loop() { val = digitalRead(inputPin); if (val != valOld) { if (val == HIGH) { Serial.println("C02"); } else { Serial.println("C01"); }; } valOld = val; //moved outside of if/then statement delay(500); }
-
03-10-2018, 11:54 PM #15
- Join Date
- Mar 2018
- Location
- Chandigarh India
- Posts
- 2
Re: Turning switches off
Hi,
I am new to arduino and Link2Fs, The above code is for a single switch, Could anyone please help me with the code if i wanted to have multiple switches.
Thanks,
-
03-11-2018, 02:15 PM #16
Re: Turning switches off
Welcome. Happy to see some beginner Arduino, Link2FS activity.
EDIT
My apologies to karen_maverick. My original post has been expanded and moved into a new thead. http://www.mycockpit.org/forums/show...105#post171105---CYXD ----- TWR --- GND ------ Closed
ILS-- NDB -- 119.1 -- 121.9 ---- 11/2013
-
03-12-2018, 01:58 PM #17
- Join Date
- Mar 2018
- Location
- Chandigarh India
- Posts
- 2
Re: Turning switches off
Thanks for the quick reply.
Thank you bbruechmann for the reply. I solved the problem. It was my overclocked CPU that made the...
Engine failure and restart while...