Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Unary Simon


  • Please log in to reply
7 replies to this topic

#1 Corey Kosak

Corey Kosak

    Advanced Member

  • Members
  • PipPipPip
  • 276 posts
  • LocationHoboken, NJ

Posted 05 October 2010 - 01:59 AM

Hello all, Being a total newbie to the Netduino (I bought the Plus at Maker Faire), I wanted an excuse to write a program for it. Unfortunately at the moment I have no other hardware, so I needed to write something that used only the button and the LED. I decided to write a unary game of Simon. For those who don't know the game, it works like this. The computer presents you with a sequence of moves (e.g. red, yellow, green, red) that you need to repeat back to it. Each round has the same sequence as the previous round, plus one more move. Now if I had four colored LEDs and four pushbuttons, this game might actually be fun. In this implementation, there are numbers (1,2,3,4) rather than colors, and communication happens between human and computer in unary. The program's output is composed of LED flashes and pauses, and in turn your responses are pushbutton presses and pauses. For example, let's say it is round 3 and the program was challenging you with the sequence "3 1 2". It would show ON+ON+ON;ON;ON+ON In this textual description, "ON" is meant to indicate that the LED is on for a period of time. "+" is meant to indicate a short pause with the LED off. ";" is meant to indicate a longer pause with the LED off. To pass the round, you would need to respond to this challenge with the correct sequence, namely click click click (pause) click (pause) click click The pauses above are kind of tricky. They need to be just right, neither too short nor too long. If they are too long, you will time out and lose; if too short, the click will be interpreted as part of the previous value (and therefore you will also lose). To help you time things just right, the program will flash the LED ultra-briefly between values. (i.e. it will flash the LED briefly precisely at the end of each (pause) above, telling you it's OK to start keying in your next value) If you can survive six rounds, you will "win". When you do so, the program will reward you by blinking its LED in an excited manner. If you lose, the LED will blink slowly and mournfully. In either case, to play again (and you know you want to), just click the button again. All the constants used (to set various timings, among other things) are in the file Constants.cs. I have them set kind of fast, for Simon experts :)

Attached Files



#2 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 05 October 2010 - 02:35 AM

Hi Corey, Any chance you can take a video of the project in action? Sounds cool... Chris

#3 hari

hari

    Advanced Member

  • Members
  • PipPipPip
  • 131 posts

Posted 05 October 2010 - 03:05 AM

Very clever idea! I can imagine how tricky it is to not only measure the click pulse width but also timeout if user misses the sequence. Bravo!

#4 Corey Kosak

Corey Kosak

    Advanced Member

  • Members
  • PipPipPip
  • 276 posts
  • LocationHoboken, NJ

Posted 05 October 2010 - 03:21 AM

OK, here's a video:

#5 Corey Kosak

Corey Kosak

    Advanced Member

  • Members
  • PipPipPip
  • 276 posts
  • LocationHoboken, NJ

Posted 05 October 2010 - 03:45 AM

Very clever idea!
I can imagine how tricky it is to not only measure the click pulse width but also timeout if user misses the sequence.
Bravo!


Thanks! It wasn't too bad actually. I isolated that logic in the ClickMaster class, where I use a Timer and a button interrupt, communicating via AutoResetEvents. By the way, because I'm rather ignorant, I have no idea what the thread or memory model is on this device. I also don't know what I'm permitted to do inside an interrupt handler. Anyway, it did seem to "work" :unsure:

The other thing I was worried about were button bounces. Debouncing would complicate the logic somewhat. Fortunately, at least on my Netduino, I haven't noticed any button bounces yet.

#6 Eric Burdo

Eric Burdo

    Advanced Member

  • Members
  • PipPipPip
  • 130 posts

Posted 05 October 2010 - 12:52 PM

Corey... That's pretty neat. I'm going to have to load that up for the kids to play with a bit... and learn about some of the events more. :)
~ Eric D. Burdo ~ http://brick-labs.com/

Today LED's, tomorrow, the world!!! Well, OK, maybe servos.

#7 CwbhX

CwbhX

    Advanced Member

  • Members
  • PipPipPip
  • 85 posts
  • LocationNYC

Posted 16 October 2010 - 02:07 AM

Wow, Nice job! I bought one at MakerFaire, and I need to learn my way through this wonderful device. This could be very helpful! Cwbh
-Cwbh

#8 Corey Kosak

Corey Kosak

    Advanced Member

  • Members
  • PipPipPip
  • 276 posts
  • LocationHoboken, NJ

Posted 16 October 2010 - 12:06 PM

Thank you! There's so much going on inside this cute little device. Can't wait to hear about your projects!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.