Black Lives Matter - Action and Equality. ... Adafruit joins the Stop Hate for Profit campaign.
0

Newbie modifying AVR Simon Game
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Newbie modifying AVR Simon Game

by javabandit on Sat Dec 04, 2010 5:53 pm

Hi everyone!

I am making a Christmas present that includes an AVR Simon game (purchased at parallax.com using an attiny2313), and I'd like to modify the code to the game. BUT, I'm very new to this type of programming, and I could really use some help. I want to use the Simon game as a "combination lock" to open up the gift. Basically, I want to set it up so that the person receiving the gift has to repeat a sequence of 18 beeps before the micro controller turns a servo motor that will unlock the metal box housing the gift.

I built the AVR Simon game using the directions, but substituting the on-board switches for some long leads to some large switches off of the board. It works fine, is fun to play, and reminds me of my childhood in the 80's.

Next, I built a USBtinyISP programmer (from the adafruit kit) to allow me to reprogram it. I used avrdude from my linux box, and it recognizes the programmer, so I think that's ready to go.

I purchased a small servo motor to open and close the lock. It's a HEXTRONIIK HXT900 servo. I plan to hook up the motor to ground and to the PD4 pin.

Next, I went through the source code provided for the Simon game, and I tried to identify the changes that I would need to make so that after 18 correct repeats, it would power the servo. THIS is where I need help.

Here are my assumptions:

In avrsimon.h ....
add under //macros to set/clear a bit in register
#define _motoron(bit) (_cbi(LED_PORT, bit))

add
//motor pin
#define MOTOR_PIN PD4 // to use PD4 to turn the servo

change
#define EPROM_SIZE 128
to
#define EPROM_SIZE 18 // since the game "wins" when reaching EPROM_SIZE


Next, in main.c ......

add after //turnon all LED's in celebration
_motoron(MOTOR_PIN)

add in void hardware_init void
//set MOTOR_PIN to output
_sbi(LED_DDR, MOTOR_PIN);


Those are my assumptions... but I have a suspicion that the motor needs something more than that. I would really appreciate any help. I am very new to this type of programming, so I thank you for your patience.
javabandit
 
Posts: 2
Joined: Sat Dec 04, 2010 5:47 pm

Re: Newbie modifying AVR Simon Game

by javabandit on Sun Dec 05, 2010 2:41 pm

Okay, so I've been reading on the Internet and learning a bit more. Apparently the servo isn't quite as simple as I had hoped. I was thinking that I could just send a voltage to it and it would turn. Now I understand that I need to send it a Pulse Width Modulated signal.

So, what I'm thinking now is that I need to include a servo control function in my main.c or add it to my avrsimon.h file.

Could anyone point me in the right direction so that I can set this up? Thank you very much.
javabandit
 
Posts: 2
Joined: Sat Dec 04, 2010 5:47 pm

Please be positive and constructive with your questions and comments.