Search
About

Damien works with students and teacher from around the world, bringing the effective use of technology to the classroom.  

LEGO MINDSTORMS
Damien is a member of the MCP (Mindstorms Community Program), a small group of experts who collaborate with LEGO to make the MINDSTORM product better.

VEX IQ Robotics
Damien is a member of the VEX IQ Super User group, a small group of experts who collaborate with VEX to make the VEX IQ platform a better product 

 

Books

Teacher Resource Books

Global Map

See where the DomaBot and RileyRover is being used around the world

« Fix a broken EV3 button | Main | Simon Game - LEGO EV3 version »
Wednesday
Aug122015

Simon Game - VEX-IQ version

 

The game of Simon is a lot of fun for kids and adults alike.  The basic premise is this:

Device does an action (display a light, plays a sound etc.)  Player has to repeat the action (press a button corresponding to the light/sound etc).  The device then does the original action plus a new action.  Player has to repeat the sequence.  Each time the player gets the sequence right, the device adds another action onto the sequence making it harder and harder to remember.

This is my VEX-IQ version of the Simon Game.

Hardware

This project uses a VEX-IQ Smart Brain and 3 Touch LED's. Given the VEX-IQ can take up to 12 input/outputs, I could theoretically do one that had 12 TouchLED's (but I think that would prove just a little too difficult).  No other hardware other than some plates and pins to prop it up.

Software

The software is all programmed in RobotC and you can download my software here - simon.c (if you use it, please acknolowgement where appropriate and forgive any glaring errors!)

These are some of the important parts of the code

Setup

Fill the sequence array with random numbers between 0-2 to represent which TouchLED's are going to light up.

 

Flash the right sequence level

 

Check to see which TouchLED's were pressed

Check to see if the TouchLED that was pressed is the right one, if it is, then allow it to check another.

This is a nice little project for teaching arrays in the classroom.  Let me know if you use it and how you would improve on it!

EmailEmail Article to Friend

Reader Comments (2)

how u do dis

April 27, 2017 | Unregistered Commenterwilson

hi ı have got two touch led when
I get an error when I use your codes
can you help me
#pragma config(Sensor, port1, LED0, sensorVexIQ_LED)
#pragma config(Sensor, port2, LED1, sensorVexIQ_LED)
!!*//
short LEDarray[3] = {LED0, LED1};

const int length=8;
int level = 1;
int pressed = 4; //keeps track of which button was pressed (4= no button pressed)
int sequence[length];

void flash_touch(int index) {
setTouchLEDColor(LEDarray[index], colorRed);
playNote(noteA,octave2,20);
sleep(100);
setTouchLEDColor(LEDarray[index], colorNone);
sleep(200);
}

task main()
{
srand(nSysTime); // generate seed for rand() from current system time
eraseDisplay();
//Load up the sequence with a random number. rand() gives a number between 0 and 32,767.
//By doing a modulo function with 3 (%3) it will divide the random number by 3 and keep the remainder
//This will give a final number of either 0,1 or 2
for(int x=0 ; x<length; x++)
{
sequence[x] = rand()%3;
}

//Light up the TouchLED's in the correct order based on the sequence and the Level you are currently on
for(int i=0 ; i<length ; i++) {
displayCenteredBigTextLine(2, "Level: %d", level); //display what Level you're on
sleep(1000);
for (int j=0; j<level ; j++) {
flash_touch(sequence[j]);
}

//Figure out which TouchLED has been pressed.
for (int j=0; j<level ; j++)
{
pressed=4; //4 means no touchLED has been pressed
while(pressed==4)
{
if(getTouchLEDValue(LED0)){ //If TouchLED0 is pressed, then set 'pressed' to 0 and light it up
pressed=0; //blue to confirm
setTouchLEDColor(LED0,colorBlue);
//While the button is still being pushed (ie. Player hasn't taken their finger off)
//don't do any commands. (hence the empty set of {} brackets
while(getTouchLEDValue(LED0)){}
setTouchLEDColor(LED0,colorNone); //Turn off the TouchLED
}else if(getTouchLEDValue(LED1)){
pressed=1;
setTouchLEDColor(LED1,colorBlue);
while(getTouchLEDValue(LED1)){}
setTouchLEDColor(LED1,colorNone);
}else if(getTouchLEDValue(LED2)){
pressed=2;
setTouchLEDColor(LED0,colorBlue);
while(getTouchLEDValue(LED2)){}
setTouchLEDColor(LED0,colorNone);
}
}

//If the TouchLED that was pressed is the same as the sequence then that's awesome!
if(pressed==sequence[j])
{
playNote(noteF, octave2, 10);
sleep(200);
} else // if it's not the same, change the display
{
eraseDisplay();
displayCenteredBigTextLine(0, "Game Over!");
displayCenteredBigTextLine(3, "Level: %d", level);
playSound(soundWrongWay);
playSound(soundWrongWay);
playSound(soundWrongWay);
sleep(3000);
stopAllTasks();
}
}

level++; //increase the level which will add another TouchLED to the sequence.
}
//If you make it through the whole sequence -> Horray!!!!
eraseDisplay();
displayCenteredBigTextLine(0, "You Rock!");
displayCenteredBigTextLine(3, "Level: %d", level--);
playSound(soundTada);
sleep(3000);
}

March 10, 2018 | Unregistered Commenterhikmet seyhanligil

PostPost a New Comment

Enter your information below to add a new comment.
Author Email (optional):
Author URL (optional):
Post:
 
Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>