Created
September 26, 2021 20:01
-
-
Save mrchimp/5dc45ef3a55ac387eaa5ae5ebc21fc03 to your computer and use it in GitHub Desktop.
IR Controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int signal_and_noise, noise_val; | |
| float signal_val, midi_val, constrained_midi_val; | |
| const int IR_LED_PIN = 13; | |
| const int SENSOR_PIN = 17; | |
| const int MIDI_CC = 74; | |
| const int MIDI_CHANNEL = 1; | |
| const float VAL_MIN = 0; | |
| const float VAL_MAX = 100; | |
| const float MIDI_MIN = 0; | |
| const float MIDI_MAX = 127; | |
| const float VAL_RANGE = VAL_MAX - VAL_MIN; | |
| void setup() | |
| { | |
| Serial.begin(9600); | |
| pinMode(IR_LED_PIN, OUTPUT); | |
| } | |
| void loop() { | |
| digitalWrite(IR_LED_PIN, HIGH); | |
| delayMicroseconds(500); | |
| signal_and_noise = analogRead(SENSOR_PIN); | |
| digitalWrite(IR_LED_PIN, LOW); | |
| delayMicroseconds(500); | |
| noise_val = analogRead(SENSOR_PIN); | |
| signal_val = signal_and_noise - noise_val; | |
| delay(10); | |
| midi_val = constrain(((signal_val * -1) / VAL_RANGE) * MIDI_MAX, MIDI_MIN, MIDI_MAX); | |
| if (midi_val > 10) { | |
| usbMIDI.sendControlChange(MIDI_CC, midi_val, MIDI_CHANNEL); | |
| usbMIDI.send_now(); | |
| } | |
| // Serial.print(signal_and_noise); | |
| // Serial.print("\t"); | |
| // Serial.print(noise_val); | |
| // Serial.print("\t"); | |
| Serial.print(signal_val); | |
| Serial.print("\t"); | |
| Serial.println(midi_val); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment