Unknow problem with an Arduino Micro program

My code:

#include "Keyboard.h"

// Options
#define LED_PIN 4
#define BUTTON_PIN 2 
#define BUTTON_PIN_SUPORTE 3 


void setup() {
  // Apagar LEDS RX e TX
  pinMode(LED_BUILTIN_TX,INPUT);
  pinMode(LED_BUILTIN_RX,INPUT);

  // Configura PIN para LED
  pinMode(LED_PIN, OUTPUT);

  // make pin 2 an input and turn on the pull-up resistor
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  pinMode(BUTTON_PIN_SUPORTE, INPUT_PULLUP);


  // setup HID
  Keyboard.begin();
  Serial.begin(9600);
}



void loop() {
  Serial.println (digitalRead(BUTTON_PIN_SUPORTE));
  delay(100);
}

The problem:
If I coment the line pinMode(LED_PIN, OUTPUT); serial return 1

If I include that line serial return 0.

I dont know about that. Someone can explain this.

Please put your code in code tags per the sticky at the top of the forum. The forum software screws up your formatting without the tags.

1 Like

Try forming your question a bit better. Tell us what you expect and what your getting. Then tell us what you tried and the results. Remember we may be in the other room or 1/2 way around the globe from you but regardless we cannot see what you can.

Check your wiring.
It seems that pin 3 is shortcut to pin 4 or the button is missing a GND wire.

That simple program just get signal from BUTTON_PIN_SUPORTE (input button) and return your value in serial.

BUTTON_PIN_SUPORTE linked in Pin 3 port as a input signal.

Pin 3 has a button.

Button ON -> Pin 3 = GND
Button OFF -> Pin 3 = OPEN

Your board is faulty or you connected something wrong

The most likely explanation is that Pin 3 and Pin 4 are shorted together. Try adding 'digitalWrite(LED_PIN, HIGH);' to see if it makes the input from Pin 3 change to HIGH. That would tend to prove the short circuit.

void loop() {
  digitalWrite(LED_PIN, HIGH);
  Serial.println (digitalRead(BUTTON_PIN_SUPORTE));
  delay(100);
}

or

void loop() {
  digitalWrite(LED_PIN, LOW);
  Serial.println (digitalRead(BUTTON_PIN_SUPORTE));
  delay(100);
}

Serial Return 1

If I try to change Botton in Pin 3 return this:

Button ON -> Pin 3 = GND Return 0
Button OFF -> Pin 3 = OPEN Return 1

Looks like all working as it should, what is your expectation?

I did some tests with another board and it is working.

This board has a problem.

There doesn't seem to be a direct short circuit between the pins. Maybe some problems with the electrical tracks.

I couldn't find the problem. The board is out of use.

Thanks for help.

Hi,

What board????

Thanks.... Tom.. :smiley: :+1: :coffee: :australia:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.