I'm using an IR sensor, dividing the value by 4 and sending that value as values for a CC number, which controls a parameter in ableton. However, the signal is far too erratic, it jumps about. Is there any way to "smooth" the signal so that I've got some kind of control over it with my hand?
Here's the code, comments appreciated!
// send continuous CC vales
#include <MIDI.h>
MIDI_CREATE_DEFAULT_INSTANCE();
int current;
void setup() {
// Serial.begin(9600); // open the serial port at 9600 bps:
MIDI.begin(1); // set up midi
}
void loop()
{
current = analogRead(0) / 4; // divide value to reduce range
MIDI.sendControlChange(98,current,1);
delay(600);
} // end loop
I've realised that what I want is to only take readings from within a foot or so. Perhaps I should ignore readings above that and then convert the values below into somewhere from 1-127 (maximum CC range)?
BTW, I'm not getting email alerts of replies, but my email is correct in the settings - any ideas?
I have an IR Sensor hooked up to Digital Pin 8 and 9 on an Uno board and when I view the serial monitor I get 1 if it is on and 0 when it is off....maybe this will help you...simple break down code to accomplish this below:
int ledPin = 13;
int IRSensor = 8;
#define IRONE IRSensor
#define LED ledPin
#define ON HIGH
#define OFF LOW
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(LED, OUTPUT);
// the loop routine runs over and over again forever:
void loop() {
// read the input on pins 8:
int sensorValue = digitalRead(IRONE);
// print out the value you read:
Serial.println(sensorValue);
delay(1); // delay in between reads for stability
if (sensorValue == 1 ){
digitalWrite(LED, OFF);
}
if (sensorValue == 0) {
digitalWrite(LED, ON);
}
}
If they were only looking for a simple "1" or "0" to trigger a function that would work....they could also look at the "Smoothing" example located within the Arduino software.
void loop() {
// read the input on pins 8:
int sensorValue = digitalRead(IRONE);
// print out the value you read:
Serial.println(sensorValue);
delay(1); // delay in between reads for stability
digitalWrite(LED, ! sensorValue);
}