Jump to content
  • 0

Button 1 and 2 not working HELP!


jbirriel84

Question

I have tried to make a sketch were I use button 1 to turn the LED 1 on when it's pressed and off when it is not. I get the LED to turn on with digitalWrite(ledPin, HIGH); but when I try to do something like this it does not work   {  if(btnPin1 == 1)    digitalWrite(ledPin, HIGH);       else     digitalWrite(ledPin, LOW);   }    . I have tried with both buttons and can not seem to get it to recognize the button being pressed. Is it the code?  I have the manual for revision C which I do not know what revision mine is but I bought it recently so I figured it had to be RevC. Another thing when my board was new i had to flash the bootloader because in MPLAB IPE not IDE I think I erased the loader so I uploaded it again everything else looks like its working normal just the buttons that I can't figure out. Could I get some help please.

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

Hi jbirriel84,

Presuming you have the bootloader back on your board, the issue you're running into is that the MPIDE does not recognize the pin names you are naming since each button and LED has a set name that is already predefined.

You can find out these names that MPIDE will recognize by going into your main MPIDE folder>hardware>pic32>variants>name_of_the_board_you're_using>Board_defs.h and then finding where it has LED Declarations and Button Declarations.

For your reference, here are the names (and pin numbers that you would use if you so chose) of the LEDs and Buttons on the chipKIT Pro MX4

#define    PIN_LED1    64
#define    PIN_LED2    65
#define    PIN_LED3    66
#define    PIN_LED4    67

#define    PIN_BTN1    42    
#define    PIN_BTN2    43

Let me know if you have any more questions.

Thanks,
JColvin

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...