1

I'm getting an error on line 9 for some reason, (digitalWrite(Sender, HIGH);), and I just cant figure out why. My goal is to have two sets of flashing patterns, one for each switch state. I don't know how important this is but I'm using an Arduino 101. This is also my first day programming so the answer could be staring me right in the nose, (in fact, I would prefer that haha). Thank you for your time!

// Starting this by declairing intigers
int Sender = 2; // Switch Out on pin two
int LedG = 10; // LED Green out on pin ten
int LedR = 11; // LED Red out on pin eleven
int Reader = 12; // Switch Input on pin twelve
//configuring I/O
pinMode(Sender = OUTPUT); // Setting pin two to output 
pinMode(Reader = INPUT); // Making pin 12 set to read switch data
digitalWrite(Sender, HIGH); //Making pin two hot
//main loop
void loop() {
 if (digitalRead (Reader) == HIGH) { // if Switch input is reading on than do pattern A
 digitalWrite(LedG, HIGH); //turning on green led
 delay(50); //delay next instruction
 digitalWrite(LedG, LOW); //turn green led off
 digitalWrite(LedR, HIGH); //turn red led on
 delay(50); //delay next instruction
 digitalWrite(LedR, LOW); //turn red led off
 }
 else { //if switch input is readion off than play pattern b
 digitalWrite(LedR, HIGH); //turn red led on
 delay(1000); //delay next instruction
 digitalWrite(LedR, LOW); //turn red led off
 digitalWrite(LedG, HIGH); //turning on green led
 delay(1000); //delay next instruction
 digitalWrite(LedG, LOW); //turn green led off
 }
}
asked Oct 16, 2016 at 14:53

1 Answer 1

3

I notice that your pinMode function calls are not quite correct:

pinMode(Sender = OUTPUT); // Setting pin two to output 
pinMode(Reader = INPUT); // Making pin 12 set to read switch data

Should be:

pinMode(Sender, OUTPUT); // Setting pin two to output 
pinMode(Reader, INPUT); // Making pin 12 set to read switch data

Refer to https://www.arduino.cc/en/Reference/PinMode for more information.

And the whole section where you configure your I/O should be wrapped inside the setup() function.

//configuring I/O
void setup()
{
 pinMode(Sender, OUTPUT); // Setting pin two to output 
 pinMode(Reader, INPUT); // Making pin 12 set to read switch data
 digitalWrite(Sender, HIGH); //Making pin two hot
}
answered Oct 16, 2016 at 15:06
2
  • Incidentally, my if statement doesn't seem to be functioning correctly. Is (if (digitalRead (Reader) == HIGH)) the correct way to check if an input is true? Commented Oct 16, 2016 at 15:25
  • Never mind, sorry. Commented Oct 16, 2016 at 15:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.