Recent Posts

Pages: [1] 2 3 ... 10
1
If it helps, the original code built for a Nano, using fewer keys.

The setup()

Code: [Select]
void setup()
{
  /* Initialise the LCD */
  lcd.init();
  lcd.init();
  /* Make sure the backlight is turned on */
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print(" *WOMinator* (c)");
  lcd.setCursor(0,1);
  lcd.print("2012 L O'Donnell");

 DDRB=B11111111; // All outputs for matrix and LEDs (bits 6 and 7 not used)
 DDRC=B11111111; // All outputs
 DDRD=B00000010; // All inputs except  USB TX

 for (int i=2; i<8; i++)  // Setup the row pins 2..7 as INPUTs
 {
  digitalWrite(i,HIGH);  // Turn on the pull-up resistors on the inputs
 }

 for (int i=12; i<18; i++)  // Turn pins 12-17 high (inactive)
 {
  digitalWrite(i,HIGH);  // Turn on
 }

for (int i=0;i<13;i++)  // Ensure arrays are cleared
 {
  keyActive[i]=0;
  lastKeyActive[i]=0;
  keyTimer[i]=0;
 }

 mySerial.begin(31250);  // Initialise Midi Out port
 Serial.begin(38400);    // Debugging output on normal UART back through USB
  delay(2000);    // Time to read startup message
  lcd.setCursor(0,0);
  lcd.print("PROG OCT CH MODE");
  lcd.setCursor(0,1);
  lcd.print("   1   0 01 POLY");
}




The scanKeys()

Code: [Select]
void scanKeys()
{
  for (int i=0; i<5; i++)  // Turn pins 12-17 high (inactive) -- should be 18 once function keys in place
 {
  digitalWrite(i+12,LOW);  // Turn low
  input_port=PIND;
 
   if( ( ((input_port & B00000100)>>2) ==1) && ((input_port & B00001000)>>3) ==0)  { keyActive[(i*3)]=1; } else { keyActive[(i*3)]=0; }    // NC contact open, NO contact closed = key on, array loc 0,6,12

   if( ( ((input_port & B00000100)>>2) ==1) && (((input_port & B00001000)>>3) ==1) && (keyActive[(i*3)]==0) && (keyTimer[(i*3)]!=0))  { keyTimer[(i*3)]--; if (keyTimer[(i*3)]<0) {keyTimer[(i*3)]=0;} }    // previously off key in transition
   if( ( ((input_port & B00000100)>>2) ==1) && (((input_port & B00001000)>>3) ==1) && (keyActive[(i*3)]==0) && (keyTimer[(i*3)]==0))  { keyTimer[(i*3)]=127; }    // previously off key in transition

 if(i<4) {  // Row 4,5 is special case as only 1 key
   if( ( ((input_port & B00010000)>>4) ==1) && ((input_port & B00100000)>>5) ==0)  { keyActive[(i*3)+1]=1; } else { keyActive[(i*3)+1]=0; } // NC contact open, NO contact closed = key on
   if( ( ((input_port & B01000000)>>6) ==1) && ((input_port & B10000000)>>7) ==0)  { keyActive[(i*3)+2]=1; } else { keyActive[(i*3)+2]=0; } // NC contact open, NO contact closed = key on

   if( ( ((input_port & B00010000)>>4) ==1) && (((input_port & B00100000)>>5) ==1) && (keyActive[(i*3)+1]==0) && (keyTimer[(i*3)+1]!=0))  { keyTimer[(i*3)+1]--; if (keyTimer[(i*3)]<0) {keyTimer[(i*3)]=0;} }    // previously off key in transition
   if( ( ((input_port & B00010000)>>4) ==1) && (((input_port & B00100000)>>5) ==1) && (keyActive[(i*3)+1]==0) && (keyTimer[(i*3)+1]==0))  { keyTimer[(i*3)+1]=127; }    // previously off key in transition

   if( ( ((input_port & B01000000)>>6) ==1) && (((input_port & B10000000)>>7) ==1) && (keyActive[(i*3)+2]==0) && (keyTimer[(i*3)+2]!=0))  { keyTimer[(i*3)+2]--; if (keyTimer[(i*3)+2]<0) {keyTimer[(i*3)+2]=0;} }    // previously off key in transition
   if( ( ((input_port & B01000000)>>6) ==1) && (((input_port & B10000000)>>7) ==1) && (keyActive[(i*3)+2]==0) && (keyTimer[(i*3)+2]==0))  { keyTimer[(i*3)+2]=127; }    // previously off key in transition

   }   

// for velocity sensitivity, we need to watch for NC and NO bit both being 1 (pedal in transition) when it was previously keyActive=0 and start counting. Stop when NC=1 and NO=0 (contact made)

  digitalWrite(i+12,HIGH);  // Turn high = inactive
 }
}


and scanButtons()

Code: [Select]
void scanButtons() {
  digitalWrite(17,LOW);  // Turn buttons row low
  input_port=PIND;
 
  buttonActive[0]=(input_port & B00000100)>>2;  // oct down
  buttonActive[1]=(input_port & B00001000)>>3;  // oct up
  buttonActive[2]=(input_port & B00010000)>>4;  // prog down
  buttonActive[3]=(input_port & B00100000)>>5;  // prog up
  buttonActive[4]=(input_port & B01000000)>>6;  // mode
  buttonActive[5]=(input_port & B10000000)>>7;  // function

  digitalWrite(17,HIGH);  // Turn high = inactive

  for (int i=0; i<6; i++)  // check for changes
   {
      if(buttonActive[i]==0 && lastButtonActive[i]==0) // Button pressed since last time (0=active for input, 1=active for last array)
      {
        lastButtonActive[i]=1;
       
        if(i==0)  {
            turnNoteOff(currentNoteVal);
            globTranspose-=1;   // Go down an octave
            if(globTranspose<-3) { globTranspose=-3; }  // If we're beyond 3 octaves down then reset to 3 octaves down
            if (globTranspose==0) { octDownLED=0; octUpLED=0; octUpRate=0; octDownRate=0; }  // No lights as we're not transposed
            else if (globTranspose<0)  { octDownRate=-globTranspose; octUpRate=0; }  // Set octave down LED going at appropriate speed, turn off Up LED
            else { octUpRate=globTranspose; octDownRate=0; }  // Set octave up LED going at appropriate speed, turn off down LED
          }
        else if(i==1)  {
            turnNoteOff(currentNoteVal);
            globTranspose+=1;   // Go up an octave
            if(globTranspose>3) { globTranspose=3; }  // If we're beyond 3 octaves up then reset to 3 octaves up
            if (globTranspose==0) { octDownLED=0; octUpLED=0; octUpRate=0; octDownRate=0; }  // No lights as we're not transposed
            else if (globTranspose<0)  { octDownRate=-globTranspose; octUpRate=0; }  // Set octave down LED going at appropriate speed, turn off Up LED
            else { octUpRate=globTranspose; octDownRate=0; }  // Set octave up LED going at appropriate speed, turn off down LED
        }
        else if(i==2)  {
            progNumber--;
            if(progNumber<1) { progNumber=1; }  // If we're beyond 1 prog, set to 1
            sendProgChange();
        }
        else if(i==3)  {
            progNumber++;
            if(progNumber>127) { progNumber=127; }  // If we're beyond 127 prog, set to 127
            sendProgChange();
        }
        else if(i==4)  {
            playMode=~playMode;  // invert the playmode value
            if(playMode==0) { modeLED=0; modeRate=0; turnNoteOff(currentNoteVal); }  // turn LED off and turn off any previously sounding note
            else { modeRate=1;  }  // start LED throbbing
           
            // TODO - change code to sustain last note on
        }
        else if(i==5)  {
           // TODO - implement function switch mode
        }

      } 
      else if(buttonActive[i]==1 && lastButtonActive[i]==1) // Button released since last time - shouldn't need to do anything but track it
      {
        lastButtonActive[i]=0;
      } 
   }
}
2
Quote
it wouldn't be that hard to add a function prototype and use that as the center of discussion.
I think the example using hard-coded values sucks. Using variables with the names mentioned before the example would make it clear what the inputs are.
3
What everyone else said. The most feasible way to do this is over the internet.
4
Project Guidance / Re: Zero crossing detection qu...
Last post by bangaham - Today at 01:19 am
Thanks for the clear answear. Now all that's left is to wait for the parts, write the code and tune the constants. Will do a update once I make some progress. Thanks for all the help.
5
You receive a character and next compare it with a string? Try single quotes instead of double quotes in the if condition.

6
Quote
Show us how you are sending it.
And, tell us what is sending the data. If what is sending the data is sending text, you have no choice but to read the data AS TEXT.
7
I made some changes based on what I interpreted the recognized problems in scanKeys(). This is one such change:

Code: [Select]
for (int i = 0; i < 6; i++) // Turn pins 12-17 high (inactive) -- should be 18 once function keys in place
  {
    digitalWrite(i + 8, LOW); // Turn low


We are using an Arduino Uno, Sparkfun variation. The original code that we started with was built for a Nano. We're trying to manipulate it to work on an Uno.
8
Programming Questions / Re: Touch Activated Servo
Last post by PaulS - Today at 01:13 am
Code: [Select]
      angle == 180;
That is NOT the assignment operator.
9
Programming Questions / Re: Definitions and Void Setup
Last post by PaulS - Today at 01:09 am
Take a look at your Arduino. Do you SEE a slider? Mine didn't come with one. Do you SEE a BLE? Mine didn't come with one. When you add external hardware, you should get a library that goes with the hardware. If not, that's NOT the hardware for you. Libraries come with examples.
10
I'm in the middle of a school project and am running into some issues. I'm trying to use an Arduino to sense the voltage spike from a Hall Effect sensor that is in close contact with a spinning "pick up" wheel that we had cut out from a water jet table. The pickup wheel goes onto a spinning shaft extruding from the differential of our buggy. Over the weekend we took the sensor into the lab and simulated our spinning wheel and used an oscilloscope to look at the signal and a multi-meter to test max voltage generated. The max voltage we got was .33 DCV. We found a code online for Arduino that hopefully I can post below and simply had us put one wire from the sensor into an analog input on the uno and the other wire from the sensor to ground on the uno. We opened up the serial monitor and watched the program and uno sense voltage.

My questions are, we had no time reference so is there a way to have the time posted beside the voltage value in the serial monitor window? Also, what is the base line sensing time that the uno is set to and how to I change it to the shortest time increments as possible. Thirdly, is there a way to set the uno up to just sense an incoming voltage when a signal is presented to the uno? I would prefer that was so if the buggy becomes stationary for a couple of minutes, the uno is not filling up pages and pages of zeros.

I honestly do not know how to write code so this has been very frustrating. The group is talking about using a raspi in conjunction with the uno but that is down the road. Thanks for the help

Pages: [1] 2 3 ... 10