daily pastebin goal
8%
SHARE
TWEET

Untitled

a guest Feb 25th, 2013 16 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <ardumidi.h>
  2. #include <ps2.h>
  3.  
  4. PS2 mouse(12, 13);
  5. unsigned int maxx,minx,maxy,miny,maxz,minz;
  6.  
  7. void kaoss_init()
  8. {
  9.   mouse.write(0xff);  // reset
  10.   mouse.read();  // ack byte
  11.   mouse.read();  // blank */
  12.   mouse.read();  // blank */
  13.   mouse.write(0xf0);  // remote mode
  14.   mouse.read();  // ack
  15.   delayMicroseconds(100);
  16.   mouse.write(0xe8);
  17.   mouse.read();  // ack byte
  18.   mouse.write(0x03); // x1  ( x1 * 64  +  x2 * 16  +  x3 * 4  +  x4   == modebyte )
  19.   mouse.read();  // ack byte
  20.   mouse.write(0xe8);
  21.   mouse.read();  // ack byte
  22.   mouse.write(0x00); // x2
  23.   mouse.read();  // ack byte
  24.   mouse.write(0xe8);
  25.   mouse.read();  // ack byte
  26.   mouse.write(0x01); // x3
  27.   mouse.read();  // ack byte
  28.   mouse.write(0xe8);
  29.   mouse.read();  // ack byte
  30.   mouse.write(0x00); // x4
  31.   mouse.read();  // ack byte
  32.   mouse.write(0xf3); // set samplerate 20 (stores mode)
  33.   mouse.read();  // ack byte
  34.   mouse.write(0x14);
  35.   mouse.read();  // ack byte
  36.   delayMicroseconds(100);
  37. }
  38.  
  39. void setup()
  40. {
  41.   Serial.begin(115200);
  42.   kaoss_init();
  43.  
  44.   maxx = 0;
  45.   minx = 32000;
  46.   maxy = 0;
  47.   miny = 32000;
  48.   maxz = 0;
  49.   minz = 32000;
  50. }
  51.  
  52.  
  53. void loop()
  54. {
  55.   byte mstat1;
  56.   byte mstat2;
  57.   byte mxy;
  58.   byte mx;
  59.   byte my;
  60.   byte mz;
  61.  
  62.   byte ledval;
  63.   byte midix;
  64.   byte midiy;
  65.   byte midiz;
  66.  
  67.   unsigned int cx,cy;
  68.  
  69.   mouse.write(0xeb);
  70.   mouse.read();
  71.  
  72.   mstat1 = mouse.read();
  73.   mxy = mouse.read();
  74.   mz = mouse.read();
  75.   mstat2 = mouse.read();
  76.   mx = mouse.read();
  77.   my = mouse.read();
  78.  
  79.  
  80.   // collect the bits for x and y
  81.   cx = (((mstat2 & 0x10) << 8) | ((mxy & 0x0F) << 8) | mx );
  82.   cy = (((mstat2 & 0x20) << 7) | ((mxy & 0xF0) << 4) | my );
  83.  
  84.  
  85.   // change the following digit to adjust the 'sensitivity' to touches  
  86.   if (mz > 2) {
  87.  
  88.     // autocalibrate
  89.  
  90.     if (cx < minx) { minx = cx; }
  91.     if (cx > maxx) { maxx = cx; }
  92.     if (cy < miny) { miny = cy; }
  93.     if (cy > maxy) { maxy = cy; }
  94.     if (mz < minz) { minz = mz; }
  95.     if (mz > maxz) { maxz = mz; }
  96.  
  97.     // determine led value (based on z value)
  98.     ledval = map(mz,minz,maxz,0,255);
  99.     analogWrite(3,ledval);
  100.  
  101.     // determine midi values
  102.     midix = map(cx,minx,maxx,0,127);
  103.     midiy = map(cy,miny,maxy,0,127);
  104.     midiz = map(mz,minz,maxz,0,127);
  105.    
  106.     midi_controller_change(0,0,midix);
  107.     midi_controller_change(0,1,midiy);
  108.     midi_controller_change(0,2,midiz);
  109.  
  110.   }
  111.    
  112.   delay(20);
  113. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top