From d1b5051f5e5db565678cab5639024c38f7c76d5b Mon Sep 17 00:00:00 2001 From: Gaudi Date: Mon, 10 Oct 2016 15:04:31 +0200 Subject: [PATCH] Added Hysteresis to Pots --- Open_Theremin_V3/EEPROM.h | 2 +- Open_Theremin_V3/application.cpp | 19 +++++++++++++------ README.md | 24 ++++++++++++++++++++++-- README.md~ | 2 ++ 4 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 README.md~ diff --git a/Open_Theremin_V3/EEPROM.h b/Open_Theremin_V3/EEPROM.h index cde75db..8253670 100644 --- a/Open_Theremin_V3/EEPROM.h +++ b/Open_Theremin_V3/EEPROM.h @@ -143,4 +143,4 @@ struct EEPROMClass{ }; static EEPROMClass EEPROM; -#endif \ No newline at end of file +#endif diff --git a/Open_Theremin_V3/application.cpp b/Open_Theremin_V3/application.cpp index bcfc514..c095237 100644 --- a/Open_Theremin_V3/application.cpp +++ b/Open_Theremin_V3/application.cpp @@ -12,6 +12,7 @@ const AppMode AppModeValues[] = {MUTE,NORMAL}; const int16_t CalibrationTolerance = 15; const int16_t PitchFreqOffset = 700; const int16_t VolumeFreqOffset = 700; +const int8_t HYST_VAL = 40; static int32_t pitchCalibrationBase = 0; static int32_t pitchCalibrationBaseFreq = 0; @@ -162,7 +163,9 @@ void Application::loop() { uint16_t volumePotValue = 0; uint16_t pitchPotValue = 0; - uint16_t registerPotValue = 0; + int registerPotValue,registerPotValueL = 0; + int wavePotValue,wavePotValueL = 0; + uint8_t registerValue = 0; @@ -170,10 +173,14 @@ void Application::loop() { pitchPotValue = analogRead(PITCH_POT); volumePotValue = analogRead(VOLUME_POT); - registerPotValue = (analogRead(REGISTER_SELECT_POT)>>8)+1; - - vWavetableSelector = analogRead(WAVE_SELECT_POT) >> 7; + registerPotValue = analogRead(REGISTER_SELECT_POT); + wavePotValue = analogRead(WAVE_SELECT_POT); + + if ((registerPotValue-registerPotValueL) >= HYST_VAL || (registerPotValueL-registerPotValue) >= HYST_VAL) registerPotValueL=registerPotValue; + if (((wavePotValue-wavePotValueL) >= HYST_VAL) || ((wavePotValueL-wavePotValue) >= HYST_VAL)) wavePotValueL=wavePotValue; + vWavetableSelector=wavePotValueL>>7; + registerValue=4-(registerPotValueL>>8); if (_state == PLAYING && HW_BUTTON_PRESSED) { _state = CALIBRATING; @@ -224,7 +231,7 @@ void Application::loop() { OCR0A = pitch & 0xff; #endif -#if SERIAL_ENABLED +#if L_ENABLED if (timerExpired(TICKS_100_MILLIS)) { resetTimer(); Serial.write(pitch & 0xff); // Send char on serial (if used) @@ -246,7 +253,7 @@ void Application::loop() { // set wave frequency for each mode switch (_mode) { case MUTE : /* NOTHING! */; break; - case NORMAL : setWavetableSampleAdvance((pitchCalibrationBase-pitch_v)/registerPotValue+2048-(pitchPotValue<<2)); break; + case NORMAL : setWavetableSampleAdvance((pitchCalibrationBase-pitch_v)/registerValue+2048-(pitchPotValue<<2)); break; }; // HW_LED2_OFF; diff --git a/README.md b/README.md index 6f5ef6c..128f3a7 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,22 @@ -# OpenTheremin_V3 -Open Source Theremin Instrument, Arudino Codes +## Open.Theremin V3 control software + +Arduino UNO Software for the Open.Theremin + +### Don't click on the files! +Click on the "Download ZIP" Button to the right or [Click here](https://github.com/GaudiLabs/OpenTheremin_V3/archive/master.zip) +Then unpack the archive. + +### Open Source Theremin based on the Arduino Platform + +Open.Theremin is an arduino shield to build the legendary music instrument invented by Leon Theremin back in 1920. The theremin is played with two antennas, one to control the pitch and one for volume. The electronic shield with two ports to connect those antennas comprises two heterodyne oscillators to measure the distance of the hand to the antenna when playing the instrument. The resulting signal is fed into the arduino. After linearization and filtering the arduino generates the instruments sound that is then played through a high quality digital analog audio converter on the board. The characteristics of the sound can be determined by a wave table on the arduino. + +For more info on the open source project and on availability of ready made shield see: + +http://www.gaudi.ch/OpenTheremin/ + +### Installation +1. Open up the Arduino IDE +2. Open the File "Open_Theremin_V3.ino" +3. Selecting the correct usb port on Tools -> Serial Port +4. Select the correct arduino board from Tools -> Board +5. Upload the code by clicking on the upload button. diff --git a/README.md~ b/README.md~ new file mode 100644 index 0000000..6f5ef6c --- /dev/null +++ b/README.md~ @@ -0,0 +1,2 @@ +# OpenTheremin_V3 +Open Source Theremin Instrument, Arudino Codes