5 years, 8 months ago.

How to use DigitalIn??!

I'm trying to turn the green led on when myinputpin is high, and red led on when myinputpin is low. But for the green LED just stays on all of the time? Please can someone advise me what I'm doing wrong, my code is below:

  1. include "mbed.h"

DigitalOut RedLED(LED_RED);

DigitalOut GreenLED(LED_GREEN);

DigitalIn myInputPin(PTA13);

int main() {

while(1) {

if(myInputPin.read()==1) {

GreenLED =0;

RedLED =1;

}

if(myInputPin.read()==0){

GreenLED=1;

RedLED =0;

}}}

With code tags it is clearer (<<code>> and <</code>>), but I don't really see an error. How are you connecting PTA13?

posted by Erik Olieman 06 Mar 2014

Just connected it directly to the ground or 3.3V. I've now changed PTA13 to PTB0 (the analogue in) and now it works! Not sure why though...

posted by Jonathan May 06 Mar 2014

maybe you had wired the wrong pin or it was bad connection..

posted by Wim Huiskamp 06 Mar 2014
Comment on this question
Be the first to answer this question.

You need to log in to post a question