Show Posts
Pages: 1 [2]
16  Forum 2005-2010 (read only) / Exhibition / Re: Touchpad Midi on: November 24, 2008, 02:57:27 pm
Hi ChrisTall,

Would you like to send me your email address in a private message. I'll send you the modified code.
However it's pretty simple. All you have to do is to remove all LCD code and to add a POTCC in the spirit of XCC. Don't hesitate to understand how this work by navigating in this website.
17  Forum 2005-2010 (read only) / Exhibition / Re: Touchpad Midi on: December 10, 2007, 01:49:25 pm
Second and last part :
Code:
/**********************************************************************
 *
 * LCD
 * Based on 4bit interface example
 * 2006 Massimo Banzi
 * Based on code written by Craig Lee 1998
 * 2007 Ludovic Drochon : LCDbar127
 *
 **********************************************************************/
 
void lcd_strobe()
{
      digitalWrite(LCD_EN,HIGH);
      digitalWrite(LCD_EN,LOW);
}

/* write a byte to the LCD in 4 bit mode */

void lcd_write(byte c)
{
      if(c & 0x80) digitalWrite(LCD_D7,HIGH); else  digitalWrite(LCD_D7,LOW);
      if(c & 0x40) digitalWrite(LCD_D6,HIGH); else  digitalWrite(LCD_D6,LOW);  
      if(c & 0x20) digitalWrite(LCD_D5,HIGH); else  digitalWrite(LCD_D5,LOW);  
      if(c & 0x10) digitalWrite(LCD_D4,HIGH); else  digitalWrite(LCD_D4,LOW);  
      lcd_strobe();
      if(c & 0x08) digitalWrite(LCD_D7,HIGH); else  digitalWrite(LCD_D7,LOW);
      if(c & 0x04) digitalWrite(LCD_D6,HIGH); else  digitalWrite(LCD_D6,LOW);  
      if(c & 0x02) digitalWrite(LCD_D5,HIGH); else  digitalWrite(LCD_D5,LOW);  
      if(c & 0x01) digitalWrite(LCD_D4,HIGH); else  digitalWrite(LCD_D4,LOW);  
      lcd_strobe();
      delayMicroseconds(40);
}

/*
 *       Clear and home the LCD
 */

void lcd_clear(void)
{
      digitalWrite(LCD_RS,LOW);

      lcd_write(0x1);
      delay(2);
}

/* write a string of chars to the LCD */

void lcd_puts(const char * s)
{
    digitalWrite(LCD_RS,HIGH);      // write characters

      while(*s) lcd_write(*s++);
}

/* write one character to the LCD */

void lcd_putch(byte c)
{
    digitalWrite(LCD_RS,HIGH); // write characters

      lcd_write(c);
}


/*
 * Go to the specified position
 */

void
lcd_goto(byte pos)
{
    digitalWrite(LCD_RS,0);

      lcd_write(0x80 + pos);
}
      
/* initialise the LCD - put into 4 bit mode */

void
lcd_init(void)
{              
  
  
  pinMode(LCD_D7,OUTPUT);            
      pinMode(LCD_D6,OUTPUT);
      pinMode(LCD_D5,OUTPUT);
      pinMode(LCD_D4,OUTPUT);
      pinMode(LCD_EN,OUTPUT);        
      pinMode(LCD_RS,OUTPUT);        
      
      digitalWrite(LCD_RS, LOW);      // write control bytes

      delay(15);// power on delay

      digitalWrite(LCD_D4, HIGH);      // init!      
      digitalWrite(LCD_D5, HIGH); //
      lcd_strobe();
      delay(5);

      lcd_strobe();// init!      
      delayMicroseconds(100);

      lcd_strobe();// init!      
      delay(5);

      digitalWrite(LCD_D4, LOW);      // set 4 bit mode
      lcd_strobe();
      delayMicroseconds(40);
      
      lcd_write(0x28);// 4 bit mode, 1/16 duty, 5x8 font, 2lines
      lcd_write(0x0C);// display on
      lcd_write(0x06);// entry mode advance cursor
      lcd_write(0x01);// clear display and reset cursor
}

void downloadcustomcharacter(int CGRAMaddress, byte character[])
{
  for (int i = 0; i<8; i++) //load character bytes in to CGRAM
  {
    lcd_putch(character[i]);  
  }
  delay(20);
}

void LCDbar127(int midiValue, short charBlock, short line)
{
  char  SmidiValue[3];
  lcd_goto(0x40*line);
  
  midiValue = constrain (midiValue, 0, 127); // limit input into 0 and 127
  int pixelPos = (midiValue  * charBlock * 5) / 127;
  int blockPos = (midiValue  * charBlock) / 127;
  
  for (short idx = 1; idx <= blockPos; idx++)
  {
    lcd_putch(5);
  }

  if (pixelPos % 5) lcd_putch(pixelPos % 5);  // display the not entire block
  blockPos++;
  
  for (short idx = blockPos ; idx < charBlock; idx++)
  {
    lcd_putch(0);
  }
 
  lcd_goto(0x40*line + charBlock);
  itoa(midiValue, SmidiValue, 10);
  if (midiValue<10) lcd_puts(" ");
  if (midiValue<100) lcd_puts(" ");
  
  lcd_puts(SmidiValue);
}

/**********************************************************************
 *
 * Main
 *
 **********************************************************************/
 
void setup() {
  delay (20);
  lcd_init();
  delay (200);
  lcd_write(0x40);
  //delay(40);
  byte barre1[] = {0x00,0x1F,0x00,0x00,0x00,0x00,0x1F,0x00}; //progress bar characters
  byte barre2[] = {0x00,0x1F,0x10,0x10,0x10,0x10,0x1F,0x00};
  byte barre3[] = {0x00,0x1F,0x18,0x18,0x18,0x18,0x1F,0x00};
  byte barre4[] = {0x00,0x1F,0x1C,0x1C,0x1C,0x1C,0x1F,0x00};
  byte barre5[] = {0x00,0x1F,0x1E,0x1E,0x1E,0x1E,0x1F,0x00};
  byte barre6[] = {0x00,0x1F,0x1F,0x1F,0x1F,0x1F,0x1F,0x00};
    
  downloadcustomcharacter (0 , barre1);
  downloadcustomcharacter (1 , barre2);
  downloadcustomcharacter (2 , barre3);
  downloadcustomcharacter (3 , barre4);
  downloadcustomcharacter (4 , barre5);
  downloadcustomcharacter (5 , barre6);

  Serial.begin(31250);// midi
  //Serial.begin(9600); //debug
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  pinMode(6, OUTPUT);
  
  mouse_init();
  
  lcd_clear();
  lcd_goto(0);
  lcd_puts("TouchPad");
  lcd_goto(0x40);
  lcd_puts("  MIDI");
}

void loop() {
  char mstat;
  char mx;
  char my;
 
  /* get a reading from the mouse */
  mouse_write(0xeb);  /* give me data! */
  mouse_read();      /* ignore ack */

  mstat = mouse_read();
  mx = mouse_read();
  my = mouse_read();
  
  if (digitalRead(4)==HIGH)
    {
      XCC += mx;
      XCC = constrain (XCC, 0 , 127);
      lcd_goto(0);
      lcd_puts("CC# on X");
      LCDbar127(XCC, 5, 1);
    }
    else if (digitalRead(5)==HIGH)
    {
      YCC += mx;
      YCC = constrain (YCC, 0 , 127);
      lcd_goto(0);
      lcd_puts("CC# on Y");
      LCDbar127(YCC, 5, 1);
    }
  else if (mx!=0 || my!=0 )
  {
    
      midivalueX += mx;
      midivalueY += my;
    
      midivalueX = constrain (midivalueX, 0 , 127);
      midivalueY = constrain (midivalueY, 0 , 127);

      midiMsg(0xb0, XCC, midivalueX);
      midiMsg(0xb0, YCC, midivalueY);

      LCDbar127(midivalueX, 5, 0);
      LCDbar127(midivalueY, 5, 1);
    }
  
  
}
 
18  Forum 2005-2010 (read only) / Exhibition / Re: Touchpad Midi on: December 10, 2007, 01:48:45 pm
Here is the complete code (first part) . It will be enhanced soon. I've tried to credit all sources. Thanks for usefull code and inspiration. Shall I write this in the playground ?

Code:
#define LCD_RS      8      // Register select
#define LCD_EN      9      // Enable
#define LCD_D4 10      // Data bits
#define LCD_D5 11      // Data bits
#define LCD_D6 12      // Data bits
#define LCD_D7 13      // Data bits

#define MDATA 2         // Mouse Data
#define MCLK 3          // Mouse Clock
 
int midivalueX;
int midivalueY;

int XCC = 19;          // Midi Continous Controler assigned by default to X
int YCC = 21;          // Midi Continous Controler assigned by default to Y

/**********************************************************************
 *
 * Mouse
 * Source : Arduino Playground
 * URL : http://www.arduino.cc/playground/ComponentLib/Ps2mouse
 * Author : Unknown
 **********************************************************************/


void gohi(int pin)
{
  pinMode(pin, INPUT);
  digitalWrite(pin, HIGH);
}

void golo(int pin)
{
  pinMode(pin, OUTPUT);
  digitalWrite(pin, LOW);
}

void mouse_write(char data)
{
  char i;
  char parity = 1;

  /* put pins in output mode */
  gohi(MDATA);
  gohi(MCLK);
  delayMicroseconds(300);
  golo(MCLK);
  delayMicroseconds(300);
  golo(MDATA);
  delayMicroseconds(10);
  /* start bit */
  gohi(MCLK);
  /* wait for mouse to take control of clock); */
  while (digitalRead(MCLK) == HIGH);
  /* clock is low, and we are clear to send data */
  for (i=0; i < 8; i++) {
    if (data & 0x01) {
      gohi(MDATA);
    }
    else {
      golo(MDATA);
    }
    /* wait for clock cycle */
    while (digitalRead(MCLK) == LOW)
      ;
    while (digitalRead(MCLK) == HIGH)
      ;
    parity = parity ^ (data & 0x01);
    data = data >> 1;
  }  
  /* parity */
  if (parity) {
    gohi(MDATA);
  }
  else {
    golo(MDATA);
  }
  while (digitalRead(MCLK) == LOW)
    ;
  while (digitalRead(MCLK) == HIGH)
    ;
  /* stop bit */
  gohi(MDATA);
  delayMicroseconds(50);
  while (digitalRead(MCLK) == HIGH)
    ;
  /* wait for mouse to switch modes */
  while ((digitalRead(MCLK) == LOW) || (digitalRead(MDATA) == LOW))
    ;
  /* put a hold on the incoming data. */
  golo(MCLK);
  //  Serial.print("done.\n");
}

/*
 * Get a byte of data from the mouse
 */
char mouse_read(void)
{
  char data = 0x00;
  int i;
  char bit = 0x01;

  //  Serial.print("reading byte from mouse\n");
  /* start the clock */
  gohi(MCLK);
  gohi(MDATA);
  delayMicroseconds(50);
  while (digitalRead(MCLK) == HIGH)
    ;
  delayMicroseconds(5);  /* not sure why */
  while (digitalRead(MCLK) == LOW) /* eat start bit */
    ;
  for (i=0; i < 8; i++) {
    while (digitalRead(MCLK) == HIGH)
      ;
    if (digitalRead(MDATA) == HIGH) {
      data = data | bit;
    }
    while (digitalRead(MCLK) == LOW)
      ;
    bit = bit << 1;
  }
  /* eat parity bit, which we ignore */
  while (digitalRead(MCLK) == HIGH)
    ;
  while (digitalRead(MCLK) == LOW)
    ;
  /* eat stop bit */
  while (digitalRead(MCLK) == HIGH)
    ;
  while (digitalRead(MCLK) == LOW)
    ;

  /* put a hold on the incoming data. */
  golo(MCLK);
  //  Serial.print("Recvd data ");
  //  Serial.print(data, HEX);
  //  Serial.print(" from mouse\n");
  return data;
}

void mouse_init()
{
  gohi(MCLK);
  gohi(MDATA);
  //  Serial.print("Sending reset to mouse\n");
  mouse_write(0xff);
  mouse_read();  /* ack byte */
  //  Serial.print("Read ack byte1\n");
  mouse_read();  /* blank */
  mouse_read();  /* blank */
  //  Serial.print("Sending remote mode code\n");
  mouse_write(0xf0);  /* remote mode */
  mouse_read();  /* ack */
  //  Serial.print("Read ack byte2\n");
  delayMicroseconds(100);
}

/**********************************************************************
 *
 * MIDI
 *
 **********************************************************************/
 
// Send a MIDI note-on message.  Like pressing a piano key
void noteOn(byte channel, byte note, byte velocity) {
  midiMsg( (0x80 | (channel<<4)), note, velocity);
}
 
// Send a MIDI note-off message.  Like releasing a piano key
void noteOff(byte channel, byte note, byte velocity) {
  midiMsg( (0x80 | (channel<<4)), note, velocity);
}
 
// Send a general MIDI message
void midiMsg(byte cmd, byte data1, byte data2) {
  //digitalWrite(ledPin,HIGH);  // indicate we're sending MIDI data
  Serial.print(cmd, BYTE);
  Serial.print(data1, BYTE);
  Serial.print(data2, BYTE);
 // digitalWrite(ledPin,LOW);
}      
19  Forum 2005-2010 (read only) / Exhibition / Touchpad Midi on: December 09, 2007, 04:19:51 pm
I've built a MIDI controller around the Arduino.

Started from a scavenged Cirque Glidepoint resistive touchpad (PS/2 compatible), 2x8 LCD (in 4 bit mode), two buttons and a serial Arduino board.



All that take place into a simple enclosure.



The buttons when pressed allow to set the Continuous Controller number by gliding the finger on the touchpad. Left for CC# linked to X and right for Y.




The LCD displays the value sent in MIDI. Some custom characters where coded into the CGRAM in order to have a sort of bar graph. The first line is for X and the second for Y.




I'will post the code after some clean up and referencing all the source. I will also code a MIDI Channel setting and maybe a Note On message.
20  Forum 2005-2010 (read only) / Exhibition / Re: Generate Control Voltage for a modular synth on: January 13, 2009, 03:21:07 pm
Nice work crx091081gb !

I intend to start a similar project but as a CV keyboard. My aim is to use the Midibox AOUT module : http://www.ucapps.de/mbhp_aout.html .
It seems well adapted to such need (but the MAX chip is costly).
21  Forum 2005-2010 (read only) / Exhibition / Re: Arduino Powered Weather Station on: February 18, 2008, 04:39:13 pm
Really nice display.
I'm working on a weather station. It has a classic 2x20 LCD display, use Dallas sensor and send the data to the net thru a Xport AR. Here's the result (graph made with JpGraph).


22  Forum 2005-2010 (read only) / Exhibition / Re: Conway's game of "Life" on: February 18, 2008, 04:32:33 pm
Here is a draft code of GoLi wich work with a MAX7219. It should work with 8 of them (work in progress). The code may be easily reuse.
Sorry for the roughly code, with french functions name inside :

Code:
#include "LedControl.h"

LedControl lc=LedControl(12,11,10,1);

#define Largeur 8
#define Hauteur 8

int analogPin = 0;
unsigned long delaytime=150;

int idx=0;
 int t1[8][8]  =  {{0, 0, 0, 1, 0, 0, 0, 0},
                   {0, 0, 1, 0, 1, 0, 0, 0},
                   {0, 1, 0, 1, 1, 0, 0, 0},
                   {1, 0, 1, 0, 0, 1, 1, 0},
                   {0, 1, 1, 0, 0, 1, 0, 1},
                   {0, 0, 0, 1, 1, 0, 1, 0},
                   {0, 0, 0, 1, 0, 1, 0, 0},
                   {0, 0, 0, 0, 1, 0, 0, 0}};
int t2[8][8];
/*******************************************************************************/
/* set all the box to zero*/

void mise_a_0(int t1[8][8],int t2[8][8])
{
  int i,j;
  for(i=0;i<Largeur;i++)
  {
    for(j=0;j<Hauteur;j++)
    {
      t1[i][j]=0;
      t2[i][j]=0;
    }
  }
}

/*******************************************************************************/
/* clear window */

void clear_fenetre()
{
  lc.clearDisplay(0);
}

/*******************************************************************************/
/* display cells */

void affiche(int t1[8][8])
{
  int i,j;
  //lc.clearDisplay(0);
  //_setcursortype(_NOCURSOR);
  //textcolor(14);
  for(i=0;i<Largeur;i++)
  {
    for(j=0;j<Hauteur;j++)
    {
      lc.setLed(0,i,j,t1[i][j]);

    }
  }
}

/*******************************************************************************/
/* compute previous generation*/

void affect_etat_precedent(int t1[8][8],int t2[8][8])
{
  int i,j;

  for(i=0;i<Largeur;i++)
  {
    for(j=0;j<Hauteur;j++)
    {
      t2[i][j]=t1[i][j];
    }
  }
}

/*******************************************************************************/
/* compute next generation */

void affect_etat_suivant(int t1[8][8],int t2[8][8])
{
  int i,j;

  for(i=0;i<Largeur;i++)
  {
    for(j=0;j<Hauteur;j++)
    {
      t1[i][j]=t2[i][j];
    }
  }
}

/*******************************************************************************/
/* compute neighborough cells */
#
void calcul_cellule(int t1[8][8],int t2[8][8])
{
  int i,j,a;

  for(i=0;i<Largeur;i++)
  {
    for(j=0;j<Hauteur;j++)
    {
      if((i==0)&&(j==0))
      {
        a=t1[i][j+1]+t1[i+1][j]+t1[i+1][j+1]+t1[i][69]+t1[i+1][69]+t1[19][j]+t1[19][j+1]+t1[19][69];
      }

      if((i!=0)&&(j!=0)&&(i!=(Largeur-1))&&(j!=(Hauteur-1)))
      {
        a=t1[i-1][j-1]+t1[i-1][j]+t1[i-1][j+1]+t1[i][j+1]+t1[i+1][j+1]+t1[i+1][j]+t1[i+1][j-1]+t1[i][j-1];
      }
      
      if((i==0)&&(j!=0)&&(j!=(Hauteur-1)))
      {
        a=t1[i][j-1]+t1[i+1][j-1]+t1[i+1][j]+t1[i+1][j+1]+t1[i][j+1]+t1[19][j-1]+t1[19][j]+t1[19][j+1];
      }

      if((i==0)&&(j==(Hauteur-1)))
      {
        a=t1[i][j-1]+t1[i+1][j-1]+t1[i+1][j]+t1[i][0]+t1[i+1][0]+t1[19][0]+t1[19][j]+t1[19][j-1];
      }
      
      if((i==(Largeur-1))&&(j==0))
      {
        a=t1[i-1][j]+t1[i-1][j+1]+t1[i][j+1]+t1[i][69]+t1[i-1][69]+t1[0][j]+t1[0][j+1]+t1[0][69];
      }
      
      if((i==(Largeur-1))&&(j!=0)&&(j!=(Hauteur-1)))
      {
        a=t1[i][j-1]+t1[i][j+1]+t1[i-1][j-1]+t1[i-1][j]+t1[i-1][j+1]+t1[0][j]+t1[0][j-1]+t1[0][j+1];
      }
      
      if((i==(Largeur-1))&&(j==(Hauteur-1)))
      {
        a=t1[i][j-1]+t1[i-1][j-1]+t1[i-1][j]+t1[0][j]+t1[0][j-1]+t1[i][0]+t1[i-1][0]+t1[0][0];
      }

      if((i!=0)&&(i!=(Largeur-1))&&(j==0))
      {
        a=t1[i-1][j]+t1[i-1][j+1]+t1[i][j+1]+t1[i+1][j+1]+t1[i+1][j]+t1[i][69]+t1[i-1][69]+t1[i+1][69];
      }

      if((i!=0)&&(i!=(Largeur-1))&&(j==(Hauteur-1)))
      {
        a=t1[i-1][j]+t1[i-1][j-1]+t1[i][j-1]+t1[i+1][j-1]+t1[i+1][j]+t1[i][0]+t1[i-1][0]+t1[i+1][0];
      }

      if((t1[i][j]==0)&&(a==3)){t2[i][j]=1;}
      if((t1[i][j]==1)&&((a==2)||(a==3))){t2[i][j]=1;}
      if((t1[i][j]==1)&&((a==1)||(a==0)||(a>3))){t2[i][j]=0;}
    }
  }
}

/*******************************************************************************/
/* randomize */

void alea(int t1[8][8])
{
  int i,j;
  randomSeed(millis());
  for(i=0;i<Largeur;i++)
  {
    for(j=0;j<Hauteur;j++)
    {
      t1[i][j]=random(2);
    }
  }
}

/*******************************************************************************/
/*permutation*/

void permut(int *a,int *b)
{
  int aux;
  aux=*a;
  *a=*b;
  *b=aux;
}





void setup() {
   lc.shutdown(0,false);
   lc.setIntensity(0,15);
   lc.clearDisplay(0);
  // alea(t1);
}


void loop()
{

   if (idx++ > 30)
   {
     alea(t1);
  
     lc.clearDisplay(0);
     delay(300);
     idx=0;
   }
    
    affect_etat_precedent(t1,t2);
    calcul_cellule(t1,t2);
    affect_etat_suivant(t1,t2);
    affiche(t1);
    delay(delaytime);
    
  
}
Pages: 1 [2]