Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 2 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:
- 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 (
posted by Erik - 06 Mar 2014<<code>> and <</code>>
), but I don't really see an error. How are you connecting PTA13?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 2014maybe you had wired the wrong pin or it was bad connection..
posted by Wim Huiskamp 06 Mar 2014