9 years, 4 months ago.

Digital In problem

Hi guys,

I have a problem with the digital inputs. My led is always on.

include the mbed library with this snippet

#include "mbed.h"

DigitalOut myled(LED1);
DigitalIn button(PB1);

int main() {
    while(1) {
        if(button){
        myled = 1;
                }
    }
}

I tried with if statement, with while statement but the result is the same. I have changed the button (pb1 -> pb0 ) i have changed the led (led1 ->led0). the result is always the same.

My button is ok i checked it with a multimeter, so there is no hardware problem. My mbed lib is updated.

This is the simplest code using digital input output, what else should I expect from more complex ones?

Any ideas?

UPDATE: Yeap thank you for your replies I managed to make the led work ! But the other questions are still a dilemma :)

Where I can find how should I declare my pins properly ??? For example if I want to configure the LCD or the touch sensor etc. Any schematic / table on how are they on datasheet and how should i declare them in mbed?

I read the GG starting guide but the declaration of the pins are different form the embed ones. For example I could not find any SW / BTN in the guide and I assume for the rest of the sensors,ADCs etc are also different.

Also I read some libraries that have pins like p10 p12 p20 what are those notations ???

Question relating to:

Silicon Labs' EFM32™ Giant Gecko ARM® Cortex®-M3 based 32-bit microcontrollers (MCUs) provide flash memory configurations up to 1024 kB, 64-128 kB of RAM and CPU speeds up to 48 MHz, …

If you want to use the display or slider, check out the following libraries: https://developer.mbed.org/teams/SiliconLabs/code/EFM32_SegmentLCD/ https://developer.mbed.org/teams/SiliconLabs/code/EFM32_CapSenseSlider/

Although we are continuously improving our mbed implementation/support, it is still in its early stages, and there are still some kinks that need to be ironed out.

posted by Srod Karim 09 Jul 2015

3 Answers

9 years, 4 months ago.

Hey Alin,

PB0 and PB1 here refer to the PinNames, portBpin0 and portBpin1, and not the buttons, PushButton0 and PushButton1. (in the schematics, these would be differentiated as MCU_PBx contra UIF_PBx)

To use the PushButtons, use SW0/SW1 or BTN0/BTN1 instead.

9 years, 4 months ago.

In addition to checking you have the correct pins (you're not the first to be confused by the naming) you will also need to make a small code change.

if(button)
  myled = 1;
else
  myled = 0;

If you don't set the pin low at some point it's just going to stay high all the time.

thank you for your answers !

are the buttons active high ?

  1. include "mbed.h"

DigitalOut myled(LED1); DigitalIn button(SW1);

int main() { while(1) { if(button==0){ myled = 1; } else myled = 0; } }

with this code the led is off and when i push the button is on ! if button == 1 the led is on all the time and when i press the button is goes off

posted by Alin Iacobscu 09 Jul 2015

I don't have that particular board so I don't know off hand if the buttons are active high or low. It is also possible that the LEDs are active low.

Edit: Looking at the schematic ( http://www.silabs.com/Support%20Documents/TechnicalDocs/BRD2200A_A03.pdf ) the buttons are active low and the LEDs are active high.

posted by Andy A 09 Jul 2015
9 years, 4 months ago.

Assuming you have a pull up resistor for the button (micro has week pull up anyway)

the default state is 1 - High, with button NOT PRESSED !!,

so when button is pressed, it is low, therefor, the led goes low / off

hope this helps,

Ceri