I have a project at school where I have to create a reaction game for two. I have little knowledge in programming. I have never been programming before but i like this subject and i think its interrestin. We have learned minimally at school. Everything should be self-taught. I can the basics.. But now i've got a huge project (for me) and i dont know where to start.
It would be of great help if someone could show me or tell me where to start. There are so many way's to do this. How would you started and end?
This is my assignment:
Create a layout with two buttons two LEDs and buzzer. A game for two players. The player who first press the button, after the buzzer has sounded get a point. This must be indicated by a led next to the button. Add 7 segment led to display the number of points to each player. If one player press too early will get a minus point.
You need help for what exactly ? It seems to be an interesting project. I'm sure that for the layout and the design you'll be better than me so I'll focus on the programmation part and give some ideas that come to me.
First thing, I'd suggest you to keep a close eye on the tutorials and the reference section of this web site it can help a lot with the language to use with your Arduino. Maybe there is some slight difference with the language you learned but you should notice a lot of similarity as well. I assume that you know the difference between the 2 mains functions setup() and loop(). I also suggest you to find some documentation and some exemples about the 7-segments-led display because I think I'll be the more difficult part of this project. There is also exemples available on the web for using active or passive buzzer. You should determine what kind of buzzer you have so you will know how to use them with your Arduino. One require only a voltage, the other require a pulse voltage at a wished frequency. (Active or passive buzzer? - Audio - Arduino Forum) You can play a music with a passive buzzer but if I would have the choice I would choose an active one, it's easier to program and it'll avoid some trouble later (Digital Output). For the buttons, you can use an external pull-up resistor (safer) or use one include internally in the Arduino (Digital INPUT).
I'll let you find on the web an exemple how to connect your buttons, the buzzer and the 7-segments-leds display to the Arduino digital pins. Be carefull, some buzzer consume a lot of current and should be driven by a separate transistor (npn by exemple). The Arduino cannot supply more than 40 mA per pin. Don't forget to use a resistor in series with your LEDs too.
For the programmation you'll need :
initiatialize your variables (before the setup function to create global variables)
initialize/declare your Arduino pins as Input or Output (into the setup function)
to store the score of each player into separate variable.
to generate a ramdom number to determine when to trigger the buzzer if it's not already done. From 15000 ms to 30000 ms by exemple. (I suggest to look at this link to learn how to manage the timer : Arduino Playground - AvoidDelay)
at all time to read if the two buttons are pressed or not (digitalRead)
if a button is pressed keep track of the first button pressed and add a point to the corresponding player (variables) and light up the corresponding LED (digitalWrite) until you reset the game for the next trial. Substract a point if pressed to early (variables).
choose and set a delay to reset the game without the risk of unwanted manipulations. By exemple 5 seconds after the first player pressed his button... That way you can determine if the second player is pressing the button to early for the next trial or not and give points accordingly...
refresh the 2 7-segments-leds displays with the actual score
execute the loop function again.
If you want you can add an option : If the two buttons are pressed at the same time for 3 seconds, then reset the scores and the game. (Or use a 3rd button for that, or simply reset the Arduino, easier)
In summary I would look at the documentation and the exemples from the web. If available for you I would setup my components on a breadboard and make the wiring connection with the Arduino. Write and debug the code with the Arduino. Once completed you can assemble your components on your layout. Test the whole project an other time.
Lucky you, I'm wandering why I had not that kind of project to do when I was at school