Maker Pro
Maker Pro

Basics of IF and Else statements (Arduino)

upload_2017-10-3_21-10-59.png

------------------------------------------------------------------------------------------------------------------------------------------------------------------------

void setup() {
pinMode(10, OUTPUT);
pinMode(2, OUTPUT);
pinMode(12, INPUT);
pinMode(A0, INPUT);
}

void loop() {
analogWrite(10, analogRead(A0)/4);
if (12==HIGH)
{
digitalWrite(2, HIGH);
}
else
{
digitalWrite(2, LOW);
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
So this is my code. I want 2 to be the same logic as pin 12. So if pin 12 is logic 1 then pin 2 should be logic 1 and if pin 12 is logic 0 then pin 2 should be logic 0.

This doesn't work... I'd appreciate if someone could tell me where I'm going wrong with the code, I can't seem to find any similar examples. Thank you
 

Attachments

  • upload_2017-10-3_21-10-42.png
    upload_2017-10-3_21-10-42.png
    390 KB · Views: 117
Top