Thank you for your reply I see what you mean about being dishonest but I can guarantee its fine... I will be taken on as an apprentice at this company so will get taught it anyways (I'm not trying to steal a code and claim its mine I just want some help) the company even said I should ask people in the forums for help if I'm stuck.
They have not stated how quick the flashing should be and how quick to react they just want to see if I can get 2 different coloured leds flashing when the switch is in 2 different positions.
I will upload my code and any pointers would be deeply appreciated.
This code worked to flash the orange led in position '1' .. I added to it thinking the green would flash in position '0' but its not that simple it seems.
okay so I've been messing around and so close to doing it but my lights are flashing in the wrong position, what am I doing wrong? green is flashing in position '1' instead of '0'
int val = 1;
void setup() {
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(8, INPUT);
}
void loop() {
val = digitalRead(8);
if (val == 0){
digitalWrite(10, HIGH);
} else {
digitalWrite(10, LOW);
}
if (val == 0){
digitalWrite(9, HIGH);
} else {
digitalWrite(9, LOW);
}
}
Quite a few things wrong. We'll take them a few at a time.
#define LED 10
#define LED 9
Here, you define a symbol "LED" and give it the value 10. But then you immediately re-define it and give it the value 9. So when the sketch runs it will only ever have the second value.
It's still messy. Click Tools->Auto Format before you post it next time.
The LEDs don't flash as such unless you use the switch do they? I doubt that's what your employers are looking for. I think they will expect the leds to continue to flash even when you are not using the switch.
They didn't specify they wanted the lights to continue to flash; just to flash once and stay on in that certain position until the switch changes position again.
Thankyou Paul I appreciate you giving up your time to help a newbie out
Sedgell95:
They didn't specify they wanted the lights to continue to flash; just to flash once and stay on in that certain position until the switch changes position again.
Are you sure? Because maybe it is a trick question. You don't even need an Arduino to do what you just described/what your code is doing. All you need is the switch, leds and resistor(s).