New Posts  All Forums:Forum Nav:

OCN Arduino Club - Page 2

post #11 of 13
Quote:
Originally Posted by FiX View Post

IIRC analogRead is not something you want to be doing a lot if you're wanting fast code.
Here's a picture of my array of Arduino related devices (excuse really crummy phone picture, was the front facing camera because I've managed to break the back one redface.gif):
Arduinos.jpg

Nice.
I figured out a simple solution to my problem by the way:
Code:
int input[] = {
B00000000,
B00000001,
B00000010,
B00000011,
B00000100,
B00000101,
B00000110,
B00000111,
B00001000,
B00001001,
B00001010,
B00001011,
B00001100,
B00001101,
B00001110,
B00001111,
B00000000,
B00010000,
B00100000,
B00110000,
B01000000,
B01010000,
B01100000,
B01110000,
B10000000,
B10010000,
B10100000,
B10110000,
B11000000,
B11010000,
B11100000,
B11110000,
B00000000,
B00000001,
B00000010,
B00000011,
B00000100,
B00000101,
B00000110,
B00000111,
B00001000,
B00001001,
B00001010,
B00001011,
B00001100,
B00001101,
B00001110,
B00001111};  //set array of port values, 0-15 are PORTB pins 8-11, 16-31 are PORTD pins 4-7, 32-47 are PORTC pins 0-1 and PORTD pins 2-3


int chanVal[48]; //initialize array to hold all 48 values to compare with old values
int oldChanVal[48];  //initialize array to hold all 48 old values to compare with new values

void setup(){

DDRB = B00001111;  // set PORTB (digital pins 8-11) to output
PORTB = B00000000;  // set PORTB to LOW
DDRD = DDRD | B11111100;  // set PORTD (digital pins 2-7) to output while making sure not to change pins 0 and 1 (TX and RX)
PORTD = B00000000;  // set PORTD to LOW
DDRC = DDRC | B000011;  // set PORTC (analog pins 0-1) to output 
PORTC = B000000;  // set PORTC to LOW
Serial.begin(31250);  //set this to 31250 for MIDI
}

void loop(){

for(int a=0; a < 48; a++){  //loop through all 48 channels
  
  if((a >= 0) && (a < 16)){  //if first 16 channels change PORTB value and assign analog value to chanVal array
    chanVal[a] = map(analogRead(A2), 0, 1023, 0, 127);  
    PORTB = input[a];
   }
  
  else if((a >= 16) && (a < 32)){  //if 2nd 16 channels change PORTD value and assign analog value to chanVal array
    chanVal[a] = map(analogRead(A3), 0, 1023, 0, 127);  
    PORTD = input[a];
   }
  
  else{  //if 3rd 16 channels change PORTD and PORTC value and assign analog value to chanVal array
    chanVal[a] = map(analogRead(A4), 0, 1023, 0, 127);  
    PORTD = input[a];
    PORTC = input[a];
   }
  
  if(abs(chanVal[a] - oldChanVal[a]) > 1){  //test to see if any of the values in the chanVal array have changed by more than one -- if so, print
    Serial.write(0xB0);
    //Serial.print("::");
    Serial.write(a);
    //Serial.print("::");
    Serial.write(chanVal[a]);
  
}
  
oldChanVal[a] = chanVal[a]; //assign chanVal values to oldChanVal before starting over  
}

delay(48);
}
sleeper cell
(10 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II X4 840 ASUS M4A89GTD-PRO/USB3 890GX (integrated) G.Skill ECO DDR3 1600 CL8 1.35V 
Hard DriveHard DriveHard DriveOS
Samsung 830 SSD OCZ Onyx solid state WD Caviar Black Win7 64bit 
CaseAudio
Define R4 M-Audio Pro USB 
  hide details  
Reply
sleeper cell
(10 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II X4 840 ASUS M4A89GTD-PRO/USB3 890GX (integrated) G.Skill ECO DDR3 1600 CL8 1.35V 
Hard DriveHard DriveHard DriveOS
Samsung 830 SSD OCZ Onyx solid state WD Caviar Black Win7 64bit 
CaseAudio
Define R4 M-Audio Pro USB 
  hide details  
Reply
post #12 of 13
Knobby knob midi controller project prototype number 2. 64 knobs working smooth as eggs. Refined the code a bit to achieve said smoothness and accommodate new multiplexing board I built that handles the 64 knobs (256 knobs is possible with this design, but that's just crazy). Multiplexing board was built from scratch by designing circuit layout with CAD -- printing layout onto transparency paper and exposing and developing light sensitive board with pattern. This one was really rough, but honestly super surprised it worked on first attempt. Next step will be coming up with ideas for a nice enclosure.














Code:
byte muxSelect[64] = {
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000000,
  B00000001,
  B00000001,
  B00000001,
  B00000001,
  B00000001,
  B00000001,
  B00000001,
  B00000001,
  B00000001,
  B00000001,
  B00000001,
  B00000001,
  B00000001,
  B00000001,
  B00000001,
  B00000001,
  B00000010,
  B00000010,
  B00000010,
  B00000010,
  B00000010,
  B00000010,
  B00000010,
  B00000010,
  B00000010,
  B00000010,
  B00000010,
  B00000010,
  B00000010,
  B00000010,
  B00000010,
  B00000010,
  B00000011,
  B00000011,
  B00000011,
  B00000011,
  B00000011,
  B00000011,
  B00000011,
  B00000011,
  B00000011,
  B00000011,
  B00000011,
  B00000011,
  B00000011,
  B00000011,
  B00000011,
  B00000011};  //set array of port values

byte muxRead[64] = {
  B00000000,
  B00010000,
  B00100000,
  B00110000,
  B01000000,
  B01010000,
  B01100000,
  B01110000,
  B10000000,
  B10010000,
  B10100000,
  B10110000,
  B11000000,
  B11010000,
  B11100000,
  B11110000,
  B00000000,
  B00010000,
  B00100000,
  B00110000,
  B01000000,
  B01010000,
  B01100000,
  B01110000,
  B10000000,
  B10010000,
  B10100000,
  B10110000,
  B11000000,
  B11010000,
  B11100000,
  B11110000,
  B00000000,
  B00010000,
  B00100000,
  B00110000,
  B01000000,
  B01010000,
  B01100000,
  B01110000,
  B10000000,
  B10010000,
  B10100000,
  B10110000,
  B11000000,
  B11010000,
  B11100000,
  B11110000,
  B00000000,
  B00010000,
  B00100000,
  B00110000,
  B01000000,
  B01010000,
  B01100000,
  B01110000,
  B10000000,
  B10010000,
  B10100000,
  B10110000,
  B11000000,
  B11010000,
  B11100000,
  B11110000};  //set array of port values

int chanVal[64]; //initialize array to hold all 64 values to compare with old values
int oldChanVal[64];  //initialize array to hold all 64 old values to compare with new values

void setup(){

  DDRB = B00001111;  // set PORTB (digital pins 8-11) to output
  PORTB = B00000000;  // set PORTB to LOW
  DDRD = DDRD | B11110000;  // set PORTD (digital pins 4-7) to output while making sure not to change pins 0 and 1 (TX and RX)
  PORTD = B00000000;  // set PORTD to LOW

  Serial.begin(31250);  //set this to 31250 for MIDI
}

void loop(){

  for(int a=0; a < 64; a++){  //loop through all 64 channels

    PORTB = muxSelect[a];
    PORTD = muxRead[a];
    chanVal[a] = map(analogRead(A0), 0, 1023, 0, 127);  

    if(abs(chanVal[a] - oldChanVal[a]) > 1){  //test to see if any of the values in the chanVal array have changed by more than one -- if so, print
      Serial.write(0xB0);
      //Serial.print("::");
      Serial.write(a);
      //Serial.print("::");
      Serial.write(chanVal[a]);
    }
    oldChanVal[a] = chanVal[a]; //assign chanVal values to oldChanVal before starting over
  }
  delay(64);
}


Edited by monoLab - 1/25/13 at 9:11pm
sleeper cell
(10 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II X4 840 ASUS M4A89GTD-PRO/USB3 890GX (integrated) G.Skill ECO DDR3 1600 CL8 1.35V 
Hard DriveHard DriveHard DriveOS
Samsung 830 SSD OCZ Onyx solid state WD Caviar Black Win7 64bit 
CaseAudio
Define R4 M-Audio Pro USB 
  hide details  
Reply
sleeper cell
(10 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II X4 840 ASUS M4A89GTD-PRO/USB3 890GX (integrated) G.Skill ECO DDR3 1600 CL8 1.35V 
Hard DriveHard DriveHard DriveOS
Samsung 830 SSD OCZ Onyx solid state WD Caviar Black Win7 64bit 
CaseAudio
Define R4 M-Audio Pro USB 
  hide details  
Reply
post #13 of 13
Sorry for the double post, but this thread needs some love... smile.gif
sleeper cell
(10 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II X4 840 ASUS M4A89GTD-PRO/USB3 890GX (integrated) G.Skill ECO DDR3 1600 CL8 1.35V 
Hard DriveHard DriveHard DriveOS
Samsung 830 SSD OCZ Onyx solid state WD Caviar Black Win7 64bit 
CaseAudio
Define R4 M-Audio Pro USB 
  hide details  
Reply
sleeper cell
(10 items)
 
  
CPUMotherboardGraphicsRAM
Phenom II X4 840 ASUS M4A89GTD-PRO/USB3 890GX (integrated) G.Skill ECO DDR3 1600 CL8 1.35V 
Hard DriveHard DriveHard DriveOS
Samsung 830 SSD OCZ Onyx solid state WD Caviar Black Win7 64bit 
CaseAudio
Define R4 M-Audio Pro USB 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Coding and Programming