[C/C++] digitalRead gives a constant HIGH result. via /r/learnprogramming


[C/C++] digitalRead gives a constant HIGH result.

I am currently trying to program a Arduino Uno as you can see HERE

What my plan is to use the pin nr:9 as a power source, which will keep the LED connected to line 3,4 lit at all times.

Additionally, the LED connected at line 1,2 should only be lit when pin nr: 7 get's a HIGH signal which should only happen when the slideswitch is in the down position.

However the LED connected to 3,4 is lit whatever position the slideswitch is in.

I am currently on my third ever day of programming so a detailed explanation for someone at beginner level would be nice.

int ledPin = 13; int powerPin = 9; int listenPin = 7; int val=0; void setup(){ pinMode(powerPin, OUTPUT); pinMode (ledPin, OUTPUT); pinMode(listenPin, INPUT); } void loop(){ digitalWrite (powerPin, HIGH); val=digitalRead(listenPin); digitalWrite(ledPin, val); } 

Submitted July 14, 2017 at 06:44AM by LazyWolverine
via reddit http://ift.tt/2tmzNhS

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s