Go Down

Topic: Tascam Porta03 mkII SPEED MOD (how to - tutorial) (Read 202 times) previous topic - next topic

Pancra85

Aug 01, 2020, 06:35 am Last Edit: Aug 01, 2020, 11:50 pm by Pancra85
--->Here is the YouTube video: https://youtu.be/eKCuoy-qmI0

ARDUINO CODE:

Code: [Select]
const int analogInPin = A4;  // speed pot
const int analogIn2Pin = A5; //stutter pot
const int analogOutPin = 10; //PWM speed output pin

int speedValuePot = 0;
int modValuePot = 0;

float modValue;
int speedValue = 0;        // value output to the PWM (analog out)
int bootSpeedValuePot;
int oldOutputValue = 0;
int randomValue;

int modCounter;
int modCounterReset;
int counterPush;

bool firstStart = 1;
bool firstSpeedPotRead = 1;
int firstStartCounter;

void setup() {

  // initialize serial communications at 9600 bps:
  //Serial.begin(9600);
  //FastPwmPin::enablePwmPin(10, 4000000L, 50);
  pinMode(analogOutPin, OUTPUT);
}

void loop() {
  setPwmFrequency(10, 1); //so the pwm frecuency becomes less audible
  modCounter++;
  counterPush++;

  // read the analog in value:
  speedValuePot = analogRead(analogInPin);
  modValuePot = analogRead(analogIn2Pin);

  // map it to the range of the analog out:
  speedValuePot = map(speedValuePot, 0, 1023, 0, 40);
  //speedValue = ((long)speedValue*speedValue*speedValue)/(50*50); //para hacerlo exponencial
  speedValuePot = speedValuePot + 40;
  speedValue = speedValuePot;

  // change the analog out value:

  if (modCounter >= modCounterReset) {
    modCounter = 0;
    modValuePot = map(modValuePot, 0, 1023, 1023, 0);
    modValuePot = ((long)modValuePot * modValuePot) / 1023; //para hacerlo exponencial
    modValue = (float)modValuePot / 1023;
    randomValue = (50 - random(100));
    modCounterReset = map(modValuePot, 0, 1023, 1, 200);
  }

  speedValue = speedValue - (modValue * randomValue);

  const byte stuckLimit = 47;
  if (speedValue <= stuckLimit) { //para que no se pare cuando es bajo el valor
    if (counterPush >= 50) {
      if (counterPush >= 100) {
        counterPush = 0;
      }
      speedValue = stuckLimit;
    }
  }

  if (speedValue >= 80) {
    speedValue = 255;
  }
  if (speedValuePot < stuckLimit && speedValue < 30) { //valor minimo. para que no se trabe con el mod cuando esta al minimo
    speedValue = 30;
//    Serial.print("seguro mod ---> pot en: ");
//    Serial.println(speedValuePot);
  }

  //SEGURO PARA DARLE POWER SI RECIEN PRENDE
  if (firstSpeedPotRead==1){
    bootSpeedValuePot = speedValuePot;
    firstSpeedPotRead = 0;
  }
 
  int needsThisSpeedToStart = 65; //en que nivel
  if (firstStart == 1) {
    firstStartCounter++;
//    Serial.print(bootSpeedValuePot);
//    Serial.print(" - ");
    //Serial.println(firstSpeedPotRead);
    if (speedValuePot < needsThisSpeedToStart) {
      speedValue = needsThisSpeedToStart;
     
    }
    if (firstStartCounter > 5000){
      firstStart = 0;
     
    }
    if ((speedValuePot > (bootSpeedValuePot + 5) || (speedValuePot < (bootSpeedValuePot - 5)))) { //si se mueve el potenciometro se cambia la velocidad
    firstStart = 0;
  }
}

//MANDA LA SALIDA-->!
analogWrite(analogOutPin, speedValue);

  // print the results to the Serial Monitor:
//  Serial.print(modValue);
//  Serial.print(", ");
//  Serial.println(speedValue);
}




void setPwmFrequency(int pin, int divisor) {
  byte mode;
  if (pin == 5 || pin == 6 || pin == 9 || pin == 10) {
    switch (divisor) {
      case 1: mode = 0x01; break;
      case 8: mode = 0x02; break;
      case 64: mode = 0x03; break;
      case 256: mode = 0x04; break;
      case 1024: mode = 0x05; break;
      default: return;
    }
    if (pin == 5 || pin == 6) {
      TCCR0B = TCCR0B & 0b11111000 | mode;
    } else {
      TCCR1B = TCCR1B & 0b11111000 | mode;
    }
  } else if (pin == 3 || pin == 11) {
    switch (divisor) {
      case 1: mode = 0x01; break;
      case 8: mode = 0x02; break;
      case 32: mode = 0x03; break;
      case 64: mode = 0x04; break;
      case 128: mode = 0x05; break;
      case 256: mode = 0x06; break;
      case 1024: mode = 0x07; break;
      default: return;
    }
    //TCCR2B = TCCR2B & 0b11111000 | mode;
    //Serial.println("error pin freq");
    //ESTA OPCION ES SOLO PARA ARDUINO UNO?
  }
}

Go Up