Pages: [1]   Go Down
Author Topic: Keyboard Legend  (Read 817 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Me and a friend have been making this project for our university coursework, its pretty simple really just 10 buttons hooked upto a speaker and then processing controls all the stuff that happens on the screen just wondering what you guys think of it, what I can do to improve it and just feedback in general really, can upload the code aswell if you want to look at it.

http://youtu.be/8i-c5sLopZ4
Logged

0
Offline Offline
Full Member
***
Karma: 4
Posts: 218
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could not recognise the song perhaps try a different one .
So when the falling blocks touch the line you play that coloured key until the end of the block yes?
Naming the note on screen and keyboard would help learners. ABCDEFGC etc isnt it?
Having it horizontal rather than vertical might also .
I'd like to see the electronics and code for one
Its always helpful to post those so others can pick pieces out to use or the whole if wanted
After all, its open sharing that's the big draw here
B+

Lua rocks!
View Profile
WWW
Personal Message (Offline)
   
Insults
« Sent to: april on: Today at 06:35:05 AM »
   Reply with quoteQuote ReplyReply Remove this messageRemove
Quote
When i tell him to B... Offf I mean it
He then gets all reasonable and better for a while

I would just prefer he b...s off .

You are acting like a pack of dogs to his aid .

This sort of language is not acceptable.

The Arduino software is free, and the people on the forum are unpaid volunteers.

Post a public apology or I will ban you.

When you get free advice you don't get to choose who replies and who doesn't. You don't demand that certain people don't respond to you.

- Moderator

get Fucked I asked nicely CLOWN !
« Last Edit: December 01, 2012, 03:12:06 am by april » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the reply, in response to your questions,
1. The notes are kinda weird because I had to try and do it myself with the help of some RTTTL conversions to get the notes right,
2. Yes
3. The plan is to get the notes in the right order but for now they are just as the song goes for example the first note uses the first key second uses the second key etc, this was just to make it easier to prototype and would be fixed properly in the final product although we dont actually have enough keys to fit all the notes and their sharp variants into the keyboard, this would have to be added, as we felt that we wanted a game more like guitar hero rather than an actual keyboard.
4. We did think about having it horizontal but we felt that it was easier to do having the notes come down as there was more space for the columns and could get clustered on smaller screens as well as it just seemed more natural for it to come down vertically.
5. Electronics will be kinda hard as it is all sealed up in that box however the code should hopefully be able to explain whats going on, there are 10 buttons connected to pins 2-11 with a speaker plugged into 12 with a USB cable connected from the arduino to the computer, code wise will put it at the below.

Arduino
Code:
//Adds the pitches header file to use
#include "pitches.h"
//Adds the button pin values
const int Button1 = 2;  
const int Button2 = 3;  
const int Button3 = 4;  
const int Button4 = 5;  
const int Button5 = 6;  
const int Button6 = 7;
const int Button7 = 8;
const int Button8 = 9;
const int Button9 = 10;
const int Button10 = 11;
const int speakerPin = 12; //Speaker

//Stores the state of the button
int state1 = 0;
int state2 = 0;
int state3 = 0;
int state4 = 0;
int state5 = 0;
int state6 = 0;
int state7 = 0;
int state8 = 0;
int state9 = 0;
int state10 = 0;

//Checks if the button is HIGH or LOW
int val1 = 0;
int val2 = 0;
int val3 = 0;
int val4 = 0;
int val5 = 0;
int val6 = 0;
int val7 = 0;
int val8 = 0;
int val9 = 0;
int val10 = 0;

//What song is currently playing?
int song1 = 0;
int song2 = 0;
int song3 = 0;
int song4 = 0;
int song5 = 0;

int state[] = {0,0,0,0,0};

void setup() {
  //Begin serial input
  Serial.begin(9600);
  
  //Declare each of the buttons to be ready for input
  pinMode(Button1, INPUT);
  
  pinMode(Button2, INPUT);
  
  pinMode(Button3, INPUT);
  
  pinMode(Button4, INPUT);
  
  pinMode(Button5, INPUT);
  
  pinMode(Button6, INPUT);
  
  pinMode(Button7, INPUT);
  
  pinMode(Button8, INPUT);
  
  pinMode(Button9, INPUT);
  
  pinMode(Button10, INPUT);
  
  //Enables the speaker pin ready for input
  pinMode(speakerPin, OUTPUT);
}

void loop()
{  
  receiveData(); //Checks what song is being played
  
  //Checks what button is being pressed
  val1 = digitalRead(Button1);
  val2 = digitalRead(Button2);
  val3 = digitalRead(Button3);
  val4 = digitalRead(Button4);
  val5 = digitalRead(Button5);
  val6 = digitalRead(Button6);
  val7 = digitalRead(Button7);
  val8 = digitalRead(Button8);
  val9 = digitalRead(Button9);
  val10 = digitalRead(Button10);
  
  //If button 1 is being pressed then play the correct note depending on the song
  if (val1 == HIGH)
  {
    //If the current song is song 1 then play the correct corresponding note
    if(song1 == 1)
    {    
      tone(speakerPin, NOTE_A4, 20);
    }
    else if(song2 == 1)
    {
      tone(speakerPin, NOTE_CS6, 20);
    }
    else if(song3 == 1)
    {
      tone(speakerPin, NOTE_E5, 20);
    }
    else if(song4 == 1)
    {
      tone(speakerPin, NOTE_B5, 20);
    }
    else if(song5 == 1)
    {
      tone(speakerPin, NOTE_G5, 20);
    }
    else
    {
      tone(speakerPin, NOTE_A4, 20);
    }
  }
  if (val2 == HIGH)
  {
    if(song1 == 1)
    {    
      tone(speakerPin, NOTE_F4, 20);
    }
    else if(song2 == 1)
    {
      tone(speakerPin, NOTE_DS6, 20);
    }
    else if(song3 == 1)
    {
      tone(speakerPin, NOTE_F5, 20);
    }
    else if(song4 == 1)
    {
      tone(speakerPin, NOTE_AS5, 20);
    }
    else if(song5 == 1)
    {
      tone(speakerPin, NOTE_C6, 20);
    }
    else
    {
      tone(speakerPin, NOTE_F4, 20);
    }
  }
  if (val3 == HIGH)
  {
    if(song1 == 1)
    {  
      tone(speakerPin, NOTE_C5, 20);
    }
    else if(song2 == 1)
    {
      tone(speakerPin, NOTE_E6, 20);
    }
    else if(song3 == 1)
    {
      tone(speakerPin, NOTE_G5, 20);
    }
    else if(song4 == 1)
    {
      tone(speakerPin, NOTE_CS6, 20);
    }
    else if(song5 == 1)
    {
      tone(speakerPin, NOTE_G6, 20);
    }
    else
    {
      tone(speakerPin, NOTE_C5, 20);
    }
  }
  if (val4 == HIGH)
  {
    if(song1 == 1)
    {    
      tone(speakerPin, NOTE_E5, 20);
    }
    else if(song2 == 1)
    {
      tone(speakerPin, NOTE_D6, 20);
    }
    else if(song3 == 1)
    {
      tone(speakerPin, NOTE_C6, 20);
    }
    else if(song4 == 1)
    {
      tone(speakerPin, NOTE_E6, 20);
    }
    else if(song5 == 1)
    {
      tone(speakerPin, NOTE_A6, 20);
    }
    else
    {
      tone(speakerPin, NOTE_E5, 20);
    }
  }
  if (val5 == HIGH)
  {
    if(song1 == 1)
    {    
      tone(speakerPin, NOTE_F5, 20);
    }
    else if(song2 == 1)
    {
      tone(speakerPin, NOTE_CS7, 20);
    }
    else if(song3 == 1)
    {
      tone(speakerPin, NOTE_D5, 20);
    }
    else if(song4 == 1)
    {
      tone(speakerPin, NOTE_DS6, 20);
    }
    else if(song5 == 1)
    {
      tone(speakerPin, NOTE_F6, 20);
    }
    else
    {
      tone(speakerPin, NOTE_F5, 20);
    }
  }
  if (val6 == HIGH)
  {
    if(song1 == 1)
    {
      tone(speakerPin, NOTE_AS4, 20);
    }
    else if(song2 == 1)
    {
      tone(speakerPin, NOTE_C7, 20);
    }
    else if(song3 == 1)
    {
      tone(speakerPin, NOTE_A5, 20);
    }
    else if(song4 == 1)
    {
      tone(speakerPin, NOTE_FS5, 20);
    }
    else if(song5 == 1)
    {
      tone(speakerPin, NOTE_B6, 20);
    }
    else
    {
      tone(speakerPin, NOTE_AS4, 20);
    }
  }
  if (val7 == HIGH)
  {
    if(song1 == 1)
    {
      tone(speakerPin, NOTE_A5, 20);
    }
    else if(song2 == 1)
    {
      tone(speakerPin, NOTE_GS6, 20);
    }
    else if(song3 == 1)
    {
      tone(speakerPin, NOTE_B5, 20);
    }
    else if(song4 == 1)
    {
      tone(speakerPin, NOTE_FS6, 20);
    }
    else if(song5 == 1)
    {
      tone(speakerPin, NOTE_C7, 20);
    }
    else
    {
      tone(speakerPin, NOTE_A5, 20);
    }
  }
  if (val8 == HIGH)
  {
    if(song1 == 1)
    {
      tone(speakerPin, NOTE_GS5, 20);
    }
    else if(song2 == 1)
    {
      tone(speakerPin, NOTE_FS6, 20);
    }
    else if(song3 == 1)
    {
      tone(speakerPin, NOTE_F6, 20);
    }
    else
    {
      tone(speakerPin, NOTE_GS5, 20);
    }
  }
  if (val9 == HIGH)
  {
    if(song1 == 1)
    {
      tone(speakerPin, NOTE_FS5, 20);
    }
    else if(song3 == 1)
    {
      tone(speakerPin, NOTE_D6, 20);
    }
    else
    {
      tone(speakerPin, NOTE_FS5, 20);
    }
  }
  if (val10 == HIGH)
  {    
    if(song1 == 1)
    {
      tone(speakerPin, NOTE_D5, 20);
    }
    else if(song3 == 1)
    {
      tone(speakerPin, NOTE_E6, 20);
    }
    else
    {
      tone(speakerPin, NOTE_D5, 20);
    }
  }
  
  // Check to see if a button has been pressed
  if(state1 != val1 || state2 != val2 || state3 != val3 || state4 != val4 || state5 != val5 || state6 != val6 || state7 != val7 || state8 != val8 || state9 != val9 || state10 != val10)
  {
    //If a button has been pressed then send the information to processing
    state1 = val1;
    state2 = val2;
    state3 = val3;
    state4 = val4;
    state5 = val5;
    state6 = val6;
    state7 = val7;
    state8 = val8;
    state9 = val9;
    state10 = val10;
    
    Serial.write(state1);
    Serial.write(state2);
    Serial.write(state3);
    Serial.write(state4);
    Serial.write(state5);
    Serial.write(state6);
    Serial.write(state7);
    Serial.write(state8);
    Serial.write(state9);
    Serial.write(state10);
  }
}

//Checks what song is currently playing
void receiveData()
{
  //Reads in the data sent from processing and determins which song is currently playing
  if(Serial.available() >= 5)
  {
    //Sets a loop to read all the data
    for(int i = 0; i < 5; i++)
    {
      state[i] = Serial.read();
      
      song1 = state[0];
      song2 = state[1];
      song3 = state[2];
      song4 = state[3];
      song5 = state[4];
    }
  }
}

Processing code is too long for here had to pastebin it
http://pastebin.com/AtqkJqsX
« Last Edit: May 10, 2012, 06:03:41 pm by maximo1491 » Logged

Offline Offline
Edison Member
*
Karma: 50
Posts: 1702
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
what I can do to improve it
You could improve the code a lot if you read up on "for" loops and the use of arrays.

Pete
Logged

Pages: [1]   Go Up
Jump to: