Simon-like game

edited April 10 in Library Questions

Hi everyone.

I'm currently trying to make a sort of Simon game, so I've already tried some code (basic code, everything I need). But, my goal is to play with a Position motor in the center of the room (with a magnet), and in the four corners of the room, there would be four different media (image, video, sound...) that would have to be reproduced when the engine points those in the correct order, by pressing their buttons. I know I have to use magnetic and pressure sensors with my MIDI interface.

At the moment, this is what I wrote :

import processing.video.*;

import ddf.minim.analysis.*;
import ddf.minim.*;
import themidibus.*;

MidiBus myBus;
Minim minim;
Movie myMovie;
AudioPlayer son; 

int etat; 
int lampe = 0;
PImage img;  
int[]valeur = new int[1];
int phase = 0; 

void setup(){
  size(1024,200);
  minim = new Minim(this);
  MidiBus.list();

  myBus = new MidiBus(this, 0, 4);
  img = loadImage("canard.jpg"); 
  son = minim.loadFile("coin.mp3", 2048);
  myMovie = new Movie(this, "Danse.mp4");

}


void controllerChange(int channel, int number, int value){
  valeur[number] = value;
  println("Capteur : " + number + " " + valeur[number]);
}


  void keyPressed() {

    if (key == 'a') {
      etat = 1;
    }
    if (key == 'z') {
      etat = 2;
    }
    if (key == 'e') {
      etat = 3;
    }
    if (key == 'r') {
      etat = 4;
    }

     if (key == 'y') {
      etat = 5;
    }

  }


void draw(){


  //image(myMovie,0,0);

switch(phase){

   case 0 : 

    phase = 1;

    break;

   case 1 : 

     phase = 2;

   break;

}


void stop(){
  minim.stop();
  super.stop();
}

My question is, is a switchcase the right solution? I'm kinda lost, because I don't know how to start. The thing is, I don't know how to make a position motor work in my code, since it has to sense each corner (this would be possible with a filter of numbers ?)

Thank you in advance.

Tagged:

Answers

  • Given the current amount of information, I cannot decide on anything concrete.

  • What is wrong with what I posted ?

  • Well, right now there's only two "phases". So, as of now, it is correct. But I do not know (I may have just failed to understand) if you have any further plans.

  • Hi @Daera

    my goal is to play with a Position motor in the center of the room (with a magnet),

    the engine points those in the correct order, by pressing their buttons.

    I don't know how to make a position motor work in my code, since it has to sense each corner

    Base on your description, we don't know much about your motor. How is it related to your magnet? What type of motor. Even better if you provide a reference to your motor... Also, how do the buttons interacts with the motor pointing in the right order? Related to the last quote, what do you mean with sensing each corner? Could the question be re-formulated by asking if the motor can keep track of its actual absolute position at all times? For example, if the motor is pointing to the corner where you display an image, after you do 10 random turns, would you be able, by using a single command, drive the motor precisely to that same corner?

    My question is, is a switchcase the right solution?

    Yes, it can be a good solution. For example, let's say you have a variable called whatCorner which is related to where your motor is pointing to (This is still something that needs to be done so I understand). Then you can do this in draw() [Here is just the pseudo code as more tinkering is needed as you will find out with movies and music)

    final int kUnknown=-1;
    final int kSpicyPattern=0;
    final int kMusicCorner=90;
    final int kImageCorner=180;
    final int kMovieCorner=270;
    
    
    int whatCorner =kUnknown;
    
    void setup() {  .....  }
    
    void draw() {
    
      switch(whatCorner) {
      case kSpicyPattern:
        execSpicyPattern();
        break;
      case kMusicCorner:
        execMusic();
        break;
      case kImageCorner:
        execShowImage();
        break;
      case  kMovieCorner:
        execShowMovie();
        break;
      default:
        break;
      }
    }
    
    
    void execSpicyPattern() {
    }
    void execMusic() {
    }
    void execShowImage() {
    }
    void execShowMovie() {
    }
    

    Every corner is managed by a single function. a function is executed in the "state" of the system... what corner is it pointing to. I hope this helps.

    Kf

  • edited April 14

    @kfrajer Hey ! Thank you for your answer.

    How is it related to your magnet? What type of motor.

    The magnet that I will be using is going to be stick to the motor, my teacher told me I had to use a position motor, which could help me to make a filter in my code for each zone (and trigger an action when it reaches a certain area). I think he told me about a Servomotor, which is used for these types of project.

    Also, how do the buttons interacts with the motor pointing in the right order? Related to the last quote, what do you mean with sensing each corner?

    In fact, my idea was to put 4 areas with movie, image, music and another thing which would probably be a basic motor, and I want to put 4 magnetic sensors in these areas, so that the buttons could sense if one area is affected. The player would know how to reproduce the actions played.

    For example, if the motor is pointing to the corner where you display an image, after you do 10 random turns, would you be able, by using a single command, drive the motor precisely to that same corner?

    The thing is, I want the motor to keep in mind the positions and trigger the action whenever the position is in between two different numbers, in order not to create confusion.

    Thank you also for your code, that is what I wanted to do. But, do you know how can I make a code for the motor ? I'm stuck at it. The filter is hard to define, would a if condition be great, if I calibrate the motor ?

  • edited April 14

    @Daera -- re:

    I think he told me about a Servomotor

    Do you have the motor already? Or do you still need to get the motor? Choose a specific motor and interface (will you be controlling it with arduino?) then write the code for that specific thing. Depending on how your motor is connected and how you are communicating with it, your code may be very different.

    Previous forum discussions of servo motor projects:

  • I don't have it yet. But, I'm willing to control it with a MIDI interface. I'll look the link, thank you @jeremydouglass

Sign In or Register to comment.