Show Posts
Pages: [1]
1  Using Arduino / Programming Questions / Re: Trying to change analog pins within this encoder code on: April 02, 2013, 09:23:48 am
I only really needed to free up A0 A1 and A2 as these were already in use with another part of the project.

2  Using Arduino / Programming Questions / Re: Trying to change analog pins within this encoder code on: April 02, 2013, 07:31:34 am
I managed to get it working with the following code smiley

Code:
/* Rotary encoder read example */
#define ENC_A 8
#define ENC_B 9
#define ENC_PORT PINB
 
void setup()
{
  /* Setup encoder pins as inputs */
  pinMode(ENC_A, INPUT);
  digitalWrite(ENC_A, HIGH);
  pinMode(ENC_B, INPUT);
  digitalWrite(ENC_B, HIGH);
  Serial.begin (115200);
  Serial.println("Start");
}
 
void loop()
{
 static uint8_t counter = 0;      //this variable will be changed by encoder input
 int8_t tmpdata;
 /**/
  tmpdata = read_encoder();
  if( tmpdata ) {
    Serial.print("Counter value: ");
    Serial.println(counter, DEC);
    counter += tmpdata;
  }
}
 
/* returns change in encoder state (-1,0,1) */
int8_t read_encoder()
{
  static int8_t enc_states[] = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};
  static uint8_t old_AB = 0;
  /**/
  old_AB <<= 2;                   //remember previous state
  old_AB |= ( ENC_PORT & 0x03 );  //add current state
  return ( enc_states[( old_AB & 0x0f )]);
}
3  Using Arduino / Programming Questions / Trying to change analog pins within this encoder code on: April 02, 2013, 07:06:50 am
Hi
I have been trying to adapt a piece of code to use other pins than the ones stated in the piece of code. at the moment analog pins 0 and 1 are used and working. the problem is the first three pins are being used for another piece of my project and this cannot be changed. Any advice on how to change the pins used for the encoder from A0 and A1 to A4  and A5 would be appreciated.

Thanks smiley

/* Rotary encoder read example */
#define ENC_A 14
#define ENC_B 15
#define ENC_PORT PINC
 
void setup()
{
  /* Setup encoder pins as inputs */
  pinMode(ENC_A, INPUT);
  digitalWrite(ENC_A, HIGH);
  pinMode(ENC_B, INPUT);
  digitalWrite(ENC_B, HIGH);
  Serial.begin (115200);
  Serial.println("Start");
}
 
void loop()
{
 static uint8_t counter = 0;      //this variable will be changed by encoder input
 int8_t tmpdata;
 /**/
  tmpdata = read_encoder();
  if( tmpdata ) {
    Serial.print("Counter value: ");
    Serial.println(counter, DEC);
    counter += tmpdata;
  }
}
 
/* returns change in encoder state (-1,0,1) */
int8_t read_encoder()
{
  static int8_t enc_states[] = {0,-1,1,0,1,0,0,-1,-1,0,0,1,0,1,-1,0};
  static uint8_t old_AB = 0;
  /**/
  old_AB <<= 2;                   //remember previous state
  old_AB |= ( ENC_PORT & 0x03 );  //add current state
  return ( enc_states[( old_AB & 0x0f )]);
}
4  Using Arduino / Sensors / Re: Help needed to replace a button with a piezo on: March 17, 2013, 05:03:50 pm
I will give it a go. Thanks smiley
5  Using Arduino / Sensors / Re: Help needed to replace a button with a piezo on: March 17, 2013, 07:00:47 am
Hi again
Thanks for the links, i am still really struggling to work out how to replace the code that uses the button to trigger pro tools with the piezo. I have connected the piezo and connected it the same as this link you kindly supplied. http://www.arduino.cc/en/Tutorial/KnockSensor. I have it working so that the light goes bright when you tap the piezo, and i am able to monitor the values that are triggered from the piezo via the monitor window. The main thing i am struggling with now is, how do i change the code so that the piezo signal replaces the button. Any advice in regard to this would be a great help. I have been reading up on the code as well as following the tutorials and have no idea what to try now.
6  Using Arduino / Sensors / Re: Help needed to replace a button with a piezo on: March 17, 2013, 03:33:43 am
Thank you for the help smiley
7  Using Arduino / Sensors / Help needed to replace a button with a piezo on: March 16, 2013, 09:53:16 pm
Hi
I am currently trying to build a drumkit that triggers sounds in pro tools. i have got it working using buttons. However I am now trying to find a way to replace the button with a piezo. Any help with this would be very apreciated.

Thanks smiley

The code below works with 8 buttons

// what midi channel we're sending on
// ranges from 0‐15
#define drumchan 9 // Equates to MIDI Channel 10
// general midi drum notes
#define note_bassdrum 36
#define note_snaredrum 38
#define note_clap 39
#define note_hihat 42
#define note_rim 45
#define note_openhat 46
#define note_hattype 51
#define note_horn 43
// define the pins we use
#define switchAPin 10
#define switchBPin 9
#define switchCPin 8
#define switchDPin 7
#define switchEPin 6
#define switchFPin 5
#define switchGPin 4
#define switchHPin 3
#define ledPin 13 // for midi out status
int switchAState = LOW;
int switchBState = LOW;
int switchCState = LOW;
int switchDState = LOW;
int switchEState = LOW;
int switchFState = LOW;
int switchGState = LOW;
int switchHState = LOW;
int currentSwitchState = LOW;
int val,t;
void setup() {
pinMode(switchAPin, INPUT);
pinMode(switchBPin, INPUT);
pinMode(switchCPin, INPUT);
pinMode(switchDPin, INPUT);
pinMode(switchEPin, INPUT);
pinMode(switchFPin, INPUT);
pinMode(switchGPin, INPUT);
pinMode(switchHPin, INPUT);
digitalWrite(switchAPin, HIGH); // turn on internal pullup
digitalWrite(switchBPin, HIGH); // turn on internal pullup
digitalWrite(switchCPin, HIGH); // turn on internal pullup
digitalWrite(switchDPin, HIGH); // turn on internal pullup
digitalWrite(switchEPin, HIGH); // turn on internal pullup
digitalWrite(switchFPin, HIGH); // turn on internal pullup
digitalWrite(switchGPin, HIGH); // turn on internal pullup
digitalWrite(switchHPin, HIGH); // turn on internal pullup
pinMode(ledPin, OUTPUT);
Serial.begin(57600); // set MIDI baud rate
}
void loop() {
// deal with switchA
currentSwitchState = digitalRead(switchAPin);
if( currentSwitchState == LOW && switchAState == HIGH ) // push
noteOn(drumchan, note_bassdrum, 100);
if( currentSwitchState == HIGH && switchAState == LOW ) // release
noteOff(drumchan, note_bassdrum, 0);
switchAState = currentSwitchState;
// deal with switchB
currentSwitchState = digitalRead(switchBPin);
if( currentSwitchState == LOW && switchBState == HIGH ) // push
noteOn(drumchan, note_snaredrum, 100);
if( currentSwitchState == HIGH && switchBState == LOW ) // release
noteOff(drumchan, note_snaredrum, 0);
switchBState = currentSwitchState;
// deal with switchC
currentSwitchState = digitalRead(switchCPin);
if( currentSwitchState == LOW && switchCState == HIGH ) // push
noteOn(drumchan, note_clap, 100);
if( currentSwitchState == HIGH && switchCState == LOW ) // release
noteOff(drumchan, note_clap, 0);
switchCState = currentSwitchState;
// deal with switchD
currentSwitchState = digitalRead(switchDPin);
if( currentSwitchState == LOW && switchDState == HIGH ) // push
noteOn(drumchan, note_hihat, 100);
if( currentSwitchState == HIGH && switchDState == LOW ) // release
noteOff(drumchan, note_hihat, 0);
switchDState = currentSwitchState;
// deal with switchE
currentSwitchState = digitalRead(switchEPin);
if( currentSwitchState == LOW && switchEState == HIGH ) // push
noteOn(drumchan, note_rim, 100);
if( currentSwitchState == HIGH && switchEState == LOW ) // release
noteOff(drumchan, note_rim, 0);
switchEState = currentSwitchState;
// deal with switchF
currentSwitchState = digitalRead(switchFPin);
if( currentSwitchState == LOW && switchFState == HIGH ) // push
noteOn(drumchan, note_openhat, 100);
if( currentSwitchState == HIGH && switchFState == LOW ) // release
noteOff(drumchan, note_openhat, 0);
switchFState = currentSwitchState;
// deal with switchG
currentSwitchState = digitalRead(switchGPin);
if( currentSwitchState == LOW && switchGState == HIGH ) // push
noteOn(drumchan, note_hattype, 100);
if( currentSwitchState == HIGH && switchGState == LOW ) // release
noteOff(drumchan, note_hattype, 0);
switchGState = currentSwitchState;
// deal with switchH
currentSwitchState = digitalRead(switchHPin);
if( currentSwitchState == LOW && switchHState == HIGH ) // push
noteOn(drumchan, note_horn, 100);
if( currentSwitchState == HIGH && switchHState == LOW ) // release
noteOff(drumchan, note_horn, 0);
switchHState = currentSwitchState;
// Send a MIDI note on message. L ‐ ike pressing a piano key
// channel ranges from 0‐15
}
void noteOn(byte channel, byte note, byte velocity) {
midiMsg( (0x90 | channel), note, velocity);
}
// Send a MIDI note‐off message. Like releasing a piano key
void noteOff(byte channel, byte note, byte velocity) {
midiMsg( (0x80 | channel), 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.write(byte(cmd));
Serial.write(byte(data1));
Serial.write(byte(data2));
digitalWrite(ledPin,LOW);
}
8  Using Arduino / Audio / Re: Struggling to get a photo cell to control velocity on: March 16, 2013, 09:11:45 pm
Thank you for the help smiley
9  Using Arduino / Audio / Struggling to get a photo cell to control velocity on: March 16, 2013, 10:54:38 am
Hi
 i am trying to write a piece of code to enable the control of velocity of a drum, i want to implement this control via a photo cell. i have adapted a piece of code to play 8 drum sounds in pro tools when a button is pressed. and i have a photo cell connected to cut the sound of certain drums completely. What i want to implement now is a control that can control the highhat peddles velocity through the  use of a photo cell. Any advice on this would be really appreciated.

Thanks smiley

this is the code below

// what midi channel we're sending on
// ranges from 0‐15
#define drumchan 9 // Equates to MIDI Channel 10
// general midi drum notes
#define note_bassdrum 36
#define note_snaredrum 38
#define note_clap 39
#define note_hihat 42
#define note_rim 45
#define note_openhat 46
#define note_hattype 51
#define note_horn 43
// define the pins we use
#define switchAPin 10
#define switchBPin 9
#define switchCPin 8
#define switchDPin 7
#define switchEPin 6
#define switchFPin 5
#define switchGPin 4
#define switchHPin 3
#define ledPin 13 // for midi out status
int switchAState = LOW;
int switchBState = LOW;
int switchCState = LOW;
int switchDState = LOW;
int switchEState = LOW;
int switchFState = LOW;
int switchGState = LOW;
int switchHState = LOW;
int currentSwitchState = LOW;
int val,t;
void setup() {
pinMode(switchAPin, INPUT);
pinMode(switchBPin, INPUT);
pinMode(switchCPin, INPUT);
pinMode(switchDPin, INPUT);
pinMode(switchEPin, INPUT);
pinMode(switchFPin, INPUT);
pinMode(switchGPin, INPUT);
pinMode(switchHPin, INPUT);
digitalWrite(switchAPin, HIGH); // turn on internal pullup
digitalWrite(switchBPin, HIGH); // turn on internal pullup
digitalWrite(switchCPin, HIGH); // turn on internal pullup
digitalWrite(switchDPin, HIGH); // turn on internal pullup
digitalWrite(switchEPin, HIGH); // turn on internal pullup
digitalWrite(switchFPin, HIGH); // turn on internal pullup
digitalWrite(switchGPin, HIGH); // turn on internal pullup
digitalWrite(switchHPin, HIGH); // turn on internal pullup
pinMode(ledPin, OUTPUT);
Serial.begin(57600); // set MIDI baud rate
}
void loop() {
// deal with switchA
currentSwitchState = digitalRead(switchAPin);
if( currentSwitchState == LOW && switchAState == HIGH ) // push
noteOn(drumchan, note_bassdrum, 100);
if( currentSwitchState == HIGH && switchAState == LOW ) // release
noteOff(drumchan, note_bassdrum, 0);
switchAState = currentSwitchState;
// deal with switchB
currentSwitchState = digitalRead(switchBPin);
if( currentSwitchState == LOW && switchBState == HIGH ) // push
noteOn(drumchan, note_snaredrum, 100);
if( currentSwitchState == HIGH && switchBState == LOW ) // release
noteOff(drumchan, note_snaredrum, 0);
switchBState = currentSwitchState;
// deal with switchC
currentSwitchState = digitalRead(switchCPin);
if( currentSwitchState == LOW && switchCState == HIGH ) // push
noteOn(drumchan, note_clap, 100);
if( currentSwitchState == HIGH && switchCState == LOW ) // release
noteOff(drumchan, note_clap, 0);
switchCState = currentSwitchState;
// deal with switchD
currentSwitchState = digitalRead(switchDPin);
if( currentSwitchState == LOW && switchDState == HIGH ) // push
noteOn(drumchan, note_hihat, 100);
if( currentSwitchState == HIGH && switchDState == LOW ) // release
noteOff(drumchan, note_hihat, 0);
switchDState = currentSwitchState;
// deal with switchE
currentSwitchState = digitalRead(switchEPin);
if( currentSwitchState == LOW && switchEState == HIGH ) // push
noteOn(drumchan, note_rim, 100);
if( currentSwitchState == HIGH && switchEState == LOW ) // release
noteOff(drumchan, note_rim, 0);
switchEState = currentSwitchState;
// deal with switchF
currentSwitchState = digitalRead(switchFPin);
if( currentSwitchState == LOW && switchFState == HIGH ) // push
noteOn(drumchan, note_openhat, 100);
if( currentSwitchState == HIGH && switchFState == LOW ) // release
noteOff(drumchan, note_openhat, 0);
switchFState = currentSwitchState;
// deal with switchG
currentSwitchState = digitalRead(switchGPin);
if( currentSwitchState == LOW && switchGState == HIGH ) // push
noteOn(drumchan, note_hattype, 100);
if( currentSwitchState == HIGH && switchGState == LOW ) // release
noteOff(drumchan, note_hattype, 0);
switchGState = currentSwitchState;
// deal with switchH
currentSwitchState = digitalRead(switchHPin);
if( currentSwitchState == LOW && switchHState == HIGH ) // push
noteOn(drumchan, note_horn, 100);
if( currentSwitchState == HIGH && switchHState == LOW ) // release
noteOff(drumchan, note_horn, 0);
switchHState = currentSwitchState;
// Send a MIDI note on message. L ‐ ike pressing a piano key
// channel ranges from 0‐15
}
void noteOn(byte channel, byte note, byte velocity) {
midiMsg( (0x90 | channel), note, velocity);
}
// Send a MIDI note‐off message. Like releasing a piano key
void noteOff(byte channel, byte note, byte velocity) {
midiMsg( (0x80 | channel), 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.write(byte(cmd));
Serial.write(byte(data1));
Serial.write(byte(data2));
digitalWrite(ledPin,LOW);
}
10  Using Arduino / General Electronics / Re: looking for a pair of sensors to detect the distance between two objects on: March 04, 2013, 07:00:17 pm
thanks for the replys, some very helpful ideas smiley

11  Using Arduino / General Electronics / Re: looking for a pair of sensors to detect the distance between two objects on: February 24, 2013, 03:39:13 pm
sorry forgot to add that there won't be a barrier between them
12  Using Arduino / General Electronics / Re: looking for a pair of sensors to detect the distance between two objects on: February 24, 2013, 03:37:41 pm
I'm trying to build a set of air drums. I want to place  sensors  on the drum sticks, that can detect how far apart the sticks are from one another. the different distances between the sticks will allow me to hopefully select what drums are being hit by the drum sticks. so i guess it might have to be accurate within around 10-15cm or so. im still not sure if this is going to be possible though.
13  Using Arduino / General Electronics / looking for a pair of sensors to detect the distance between two objects on: February 24, 2013, 03:13:20 pm
Hi

I'm not really sure if such an object/sensor exists. Im looking for a pair of sensors, that can detect how far apart from one another they are. I have been looking at infrared proximity sensors, but dont think that will be what i'm looking for.  I have also looked into a radar sensors but thats also turned out to be the wrong sensor for the job. The maximum distance i'm looking to measure between objects will be around 1 metre. If anyone has any advice on sensors etc. that would be suitable for this, it would be very much appreciated.

Thanks
Pages: [1]