1

So at my school we are preapering for a competition. They asked me to do the technical side of it. And I accepted... I was thinking of using an arduino as a usb device for the buttons. I am going to use the serial port for this. But I can't think of a way to do it in the way I want. I want to recieve the button presses fair and well. But I also want to control the lights for the buttons, from my computer. I am using Serial.printLn() to send the serial data to the computer. But how can I send serial data to the arduino without delaying other things (What happens when someone presses a button while I am sending a command?)? Thanks in advance!

4
  • I was thinking of using an arduino as a usb device for the buttons. - what do you mean here? Later you talk about sending serial data to the PC. These are different things.
    – Nick Gammon
    Nov 2 '15 at 21:09
  • So will be also be doing the programming. Since I will be writing the program, I can easily implement the serial communications. All they have to do is plug the arduino in and change the port, if it needs to. That's what I meant.
    – utkumaden
    Nov 3 '15 at 4:12
  • Serial communication is done using interrupts, and buffers. So unless you do something weird with your program, there shouldn't be much of a problem. It would be helpful to know what it is you are trying to achieve with the buttons. Something like a gameshow, where you need to detect who pressed the button first?
    – Gerben
    Nov 3 '15 at 13:48
  • Yes exactly a gameshow. I need buttons for the game. I want to be able to control the lights through the serial inteface. I cannot figure out how I am going to do it. I reckon if I call Serial.readLine() it will halt until it gets an \n
    – utkumaden
    Nov 3 '15 at 17:32
-1

The nastiest part in what you describe is likely to be the debouncing on the button, rather than the serial communication.

One easy way out is to use some form of bounceless implementation, like an optical coupler. Another is to use HW debouncing, like the MAX 6816 family.

Then you can use a loop where you alternate between serial communications and checks for the status of the buttons.

Or you can rely on interrupts for the buttons, but it's more complex and might be overkill.

2
  • I can try to debounce the button on the computer. I am also writing the code that will be used for the competition...
    – utkumaden
    Nov 2 '15 at 20:15
  • The thing is the school is sourcing the parts. I am surprised they even sourced arduinos for the physics lab.
    – utkumaden
    Nov 2 '15 at 20:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.