Hi all, after reading the Forum guidelines, and spending much time trying to solve the issue myself, I have now given up and seek the wise heads of this forum. I make no apologies - I have worked and re-worked the sketch, but still cannot get the desired result and have obviously missed the salient art of C++.
Brief outline: nano board (clone) operating in WIN10 Pro 64, Com 3-no problems being recognised. IDE compiles OK, uploads OK, but outcome only partial i.e., rapid activation with one led 'flashing' once, the other staying on? Circuit is one double pole switch to pin 2 (input) grounded via a 10K pull-down resistor, other contact to 5vdc.
Two LED's - one on pin 3, the other on pin 6 as outputs, to ground via 220 ohm resistors.
(Other IDE's e.g., examples work OK, and I have two identical nano's both of which work the same way.)
So, here is my code, which is quite simple really. and especially kept that way for me to gain a better understanding of Arduino/C++ etc: So, over to you, and I shall look forward with anticipation to an obvious answer that I have missed (not seeing the wood for the trees, etc.) Kind regards,
const int Switch = 2; // 10k pull down resistor to Gnd, switch to 5vdc
const int RedLed = 3; // pin that Red led attached to via 220ohm resistor
const int GreenLed = 6; // pin that Green led attached to via 220ohm resistor
int SwitchState = 0;
void setup()
{
pinMode(2, INPUT);
pinMode(3, OUTPUT);//Red led's
pinMode(6, OUTPUT);//Green led's
}
//read the switch position value into a variable
void loop()
{
int (SwitchState) = digitalRead(SwitchState);
//switch Down
{ if (SwitchState == LOW)
delay(50);
digitalWrite(6, LOW);//Green off
digitalWrite(3, HIGH);//Red on(Gear in transit)
delay(8000);
digitalWrite(6, HIGH); //Green on
digitalWrite(3, LOW);//Red off
}
{ if (SwitchState == HIGH)
delay(50);
digitalWrite(6, LOW); //Green Led off}
digitalWrite(3, HIGH); //Red Led on
delay(8000);
digitalWrite(3, LOW);//Red Led off
}
}