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!

asked Nov 2, 2015 at 19:22
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. Commented Nov 2, 2015 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. Commented Nov 3, 2015 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? Commented Nov 3, 2015 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 Commented Nov 3, 2015 at 17:32

1 Answer 1

-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.

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

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.