Jump to content

Marija

Members
  • Content Count

    3
  • Joined

  • Last visited

  1. Sorry I forgot to mention, but I do use external 10k pull-up resistor and it seems to work fine with it.
  2. Thank you for the help @Mention ! I didn't use INPUT_PULLUP but instead just pinMode(UP, INPUT), becaus ethe Energia documentation says I should use just INPUT if it is for external push button, not the on board one. Yes true, I don't use the flag to do anything useful, I just realized that. So basically if I leave my ISRs as they are, I won't really have code in the loop routine? Apart from printing on the serial monitor. I will try that next. I'm not completely sure how to do the debouncing. Because I don't read switch state anywhere else in the code, just in attachInterrupt. Should I read the state of each switch in the loop function and debounce each there? Or should I put it in the setup function? I know this seems basic, but I'm still a bit puzzled with the interrupts.
  3. Hi all, I'm relatively new to microcontroller programming and I'm having a few problems with a current project that I would appreciate help with. I'm using MSP430G2553 and Energia to control the speed of two vibromotors. To this I use three pushbuttons, one to change from one motor to another and two more(up and down) to increase/decrease the speed. I have 3 interrupts to do all this and I copied the code below. The program works mostly but sometimes it acts randomly, for example, increasing the speed when I press the decrease button, or not responding at all. My questions are these, they are quite simple but I am struggling quite a lot and I want to understand the basics good: 1). Am I using the interrupts correctly? Do I need to put all of them in the setup routine? Also, I have too much code in the interrupt functions, but not sure how to fix this. Should I just poll the flags in the functions and do the motor speed updating in the loop routine? Basically, and help and comments regarding the interrupts would be very helpful. 2). How do I use switch debouncing for more then one switch? I used the Energia example previously to debounce one switch but it seems complicated using that for 3 switches. int reading = digitalRead(buttonPin); if (reading != lastButtonState) { lastDebounceTime = millis(); } if ((millis( ) - lastDebounceTime) > debounceDelay) { buttonState = reading; } My current code: up_down_test.ino Thank you a lot in advance!
×
×
  • Create New...