Help fixing errors in code

A little context:
Using a Uno to program a ATtiny85. Basically the ATtiny switches two 2N7002 Mosfets. The first Mosfet is essentially a on/off. It just switches a resistor in and out of another circuit it’s hooked up to. The second Mosfet alters a tap tempo signal. Trying to read up on bytes and boolean but so far I really just don’t understand much.

Upon verifying I get this error:
/tmp/219425228/sketch_jul23a/sketch_jul23a.ino: In function ‘void loop()’:

/tmp/219425228/sketch_jul23a/sketch_jul23a.ino:79:68: error: cannot convert ‘boolean* {aka bool*}’ to ‘byte* {aka unsigned char*}’ for argument ‘5’ to ‘void doublePreset(byte, byte, byte, byte, byte*)’

doublePreset(SELPIN1, SELPIN2, SELPIN3, holdState, &lastHoldState);

^

exit status 1

Here’s the full code:

/*Pin definition
  Change these to whatever pins you want if you're using an ATmega328 or other chip
*/
#define  TEMPO_IN   0       //ATtiny Pin 5
#define  SELPIN2    1       //ATtiny Pin 6
#define  SELPIN1    2       //ATtiny Pin 7
#define  SELPIN3    3       //ATtiny Pin 2
#define  TEMPO_OUT  4       //ATtiny Pin 3

//Constants
#define  DEBOUNCE  40        //Debounce time for the footswitch
#define  PULSES  4           //Number of pulses to send to the transistor which "taps" the tempo
#define  OUTPUT_TIME  40     //Length of pulse
#define  HOLD_TIME  750      //Time it takes to trigger the presets(in ms). Make this lower if you want it to switch faster.
#define  RESET_TIME  2000    //Timeout for the tap averager


// Variables that will change
int sum;
int currentTimer[3];  // array of most recent tap counts

byte tapCount = 0;
byte pulseCount = 4;    // Tracks the number of pulses sent to pedal
byte divisor;

boolean  readingHold = true; // double preset switch reading initialized
boolean tempHoldState= true; // previous reading in hold state read routine
boolean reading  = true; // temporary button state storage (used in debounce routine)
boolean tapState = true;   // current tap button state
boolean holdState = true; //current hold button state
boolean lastTapState = true;  // the last tap button state 
boolean lastHoldState = true; //previous reading
boolean lastButtonState = false;   // the previous reading from the input pin

float tempoScale = 0.75;  // Tempo scale factor 
float interval;           //Tempo tapped in
float scaledInterval;     //The scaled Tempo

// the following variables are long's because the time, measured in miliseconds,
// will quickly become a bigger number than can be stored in an int.

unsigned long timeoutTime = 0;  // this is when the timer will trigger next 
unsigned long indicatorTimeout; // sets the turn off time for the LED
unsigned long lastDebounceTime = 0;  // the last time the output pin was toggled
unsigned long lastTap = 0; // when the last tap happened 


void setup()
{
  pinMode( TEMPO_IN, INPUT );    // tap switch - tap it to set the tempo
  pinMode( TEMPO_OUT, OUTPUT );  // Tempo output to pedal
  pinMode( SELPIN3, OUTPUT );    // Preset indicator LED
  pinMode( SELPIN1, OUTPUT );    //To MOSFET for double preset
  pinMode( SELPIN2, OUTPUT );    //To MOSFET for double preset
  
  digitalWrite(SELPIN1, HIGH);    //This sets the expression simulator to the
  digitalWrite(SELPIN2, HIGH);     //"heel down" position every time the pedal is
  digitalWrite(SELPIN3, LOW);     //power cycled.
}

void loop()
{
  //Read if there's been a tap by debouncing the switch
  tapState = debounce(&lastButtonState, &lastDebounceTime, DEBOUNCE, HOLD_TIME, TEMPO_IN, &tapCount, false, currentTimer, 3);
  
  //See if the switch has been pressed and held
  holdState = debounce(&tempHoldState, &lastDebounceTime, HOLD_TIME, DEBOUNCE, TEMPO_IN, &tapCount, true, currentTimer, 3);
  
  //Read the intervals between taps into an array and average them and then truncate to a bpm
  getTapTempo(tapState, &lastTapState, &tapCount, currentTimer, 3, &interval, &divisor, &sum, &lastTap, RESET_TIME, &pulseCount);
  
  //Scale the tempo
  scaledInterval = interval*tempoScale;
  
  //Output the tempo
  output(&timeoutTime, &indicatorTimeout, PULSES, &pulseCount, TEMPO_OUT, currentTimer, 3, scaledInterval);
  
  //Set the expression simulator MOSFETs and the indicator LED
  doublePreset(SELPIN1, SELPIN2, SELPIN3, holdState, &lastHoldState);
}
//Actuates the Preset MOSFET
void doublePreset(byte actuator, byte indicator1, byte indicator2, byte holdState, byte *lastHoldState){
  static byte holdNumber = 0;
  if(holdState == LOW && holdState != *lastHoldState){
    switch(holdNumber){
    case 1:
      digitalWrite(actuator, HIGH);
      digitalWrite (indicator1, HIGH);
      digitalWrite (indicator2, LOW);
      holdNumber = 0;
     break;

    case 0:
      digitalWrite(actuator, LOW);
      digitalWrite (indicator1, LOW);
      digitalWrite (indicator2, HIGH);
      holdNumber = 1; //sends it back to second if statement on next button press
      break;
    }
  }
  *lastHoldState = holdState; // keep track of the state for the next loop
  return;
}

//Debounces the footswitch
boolean debounce(boolean *lastButtonState, unsigned long *lastDebounceTime, int downTime, byte upTime, byte readPin, byte *tapCount, boolean hold, int valuesArray[], byte arrayLength)
{
  boolean stateTap = true;
  boolean stateHold = true;
  boolean reading = digitalRead(readPin);

  if (reading != *lastButtonState) {  // button state just changed
    *lastDebounceTime = millis();     // reset the debouncing timer
  }
  if(hold == false){
    if ((millis() - *lastDebounceTime) >= downTime && stateTap == true) {
      stateTap = reading;
    }
  }
  else if((millis() - *lastDebounceTime) >= downTime && stateHold == true){
    stateHold = reading;
  }
  else{
    stateTap = true;
    stateHold = true;
  }
  if ((millis() - *lastDebounceTime) >= upTime && stateHold == false){
    stateHold = reading;
    *tapCount = clearTaps(valuesArray, arrayLength);
  }
  *lastButtonState = reading; // save the state for comparison on the next loop

  if(hold == false){
    return stateTap;
  }
  else{
    return stateHold;
  }
}

//Fills out the tempo values array & calculates an interval
void getTapTempo(boolean trigger, boolean *lastTrigger, byte *triggerCounts, int valuesArray[], int arrayLength, float *interval, byte *divisor, int *sum, unsigned long *lastTap, int maxMillis, byte *pulseCount){
  int bpm;
  if(trigger == false && trigger != *lastTrigger){
    if(*triggerCounts != 0){
      *triggerCounts += 1;
      for(byte n = arrayLength - 1; n > 0; n--){
        valuesArray[n] = valuesArray[n - 1];
      }
      valuesArray[0] = millis() - *lastTap;
      *pulseCount = 0;  // reset pulse count to zero
      *lastTap = millis();
      *divisor = *triggerCounts - 1;
      *divisor = constrain(*divisor, 0, arrayLength);
      for(byte n = 0; n < *divisor; n++){
        *sum += valuesArray[n];
      }
      *interval = *sum / *divisor;
      bpm = 1.0/(*interval/60000);
      *interval = 60000/bpm;
      *sum = 0;
    }
    else{
      *lastTap = millis();
      *triggerCounts += 1;
    }    
  }
  *lastTrigger = trigger;

  if(millis() - *lastTap >= maxMillis){
    *triggerCounts = clearTaps(currentTimer, arrayLength);
    *sum = 0;
  }
  return;
}

//Outputs the pulses to the MOSFET to pull the tempo footswitch LOW
void output(unsigned long *timeoutTime, unsigned long *indicatorTimeout, byte pulses, byte *pulseCount, byte outputPin, int currentTimer[], byte arrayLength, float interval){
  // check for timer timeout 
  if (millis() >= *timeoutTime && *pulseCount < pulses)  // it's time to send the output pulse
  {
    *pulseCount += 1; // keep track of how many pulses we've sent

    *indicatorTimeout = millis() + OUTPUT_TIME;  // set the time for the output to turn back off 

    *timeoutTime = millis() + interval; // set the time for the next output pulse
  }

  // send the output pulse to the LED and the transistor

  if( millis() < *indicatorTimeout ) {
    digitalWrite(outputPin, HIGH );
  }
  else {
    digitalWrite(outputPin, LOW );
  }

  if (*pulseCount > pulses - 1){
    clearTaps(currentTimer, arrayLength);
  }
  return;
}

//Clears currentTimer array when called
byte clearTaps(int valuesArray[], int arrayLength){
  byte taps = 0;
  for(byte t = 0; t < arrayLength; t++){
    valuesArray[t] = 0;
    if(valuesArray[t + 1] == 0){
      break;
    }
  }
  return taps;
}
boolean lastHoldState = true; //previous reading
...
  doublePreset(SELPIN1, SELPIN2, SELPIN3, holdState, &lastHoldState);
...
void doublePreset(byte actuator, byte indicator1, byte indicator2, byte holdState, byte *lastHoldState){

You can see that the compiler is right. "cannot convert 'boolean* {aka bool*}' to 'byte*". That is what you are attempting to do.

So I need to change all the “byte” to “boolean” or the other way around? Does it matter?

bside2234:
So I need to change all the "byte" to "boolean" or the other way around? Does it matter?

Of course it matters! What are you trying to do? It certainly depends on that! There are an infinite number of programs that compile, but don't work.

aarg:
Of course it matters! What are you trying to do? It certainly depends on that! There are an infinite number of programs that compile, but don't work.

Kind of figured. I know practically 0 coding and was given a handful of it. I'm going through it and trying to learn a little. This one threw the error in the Arduino IDE when I verified it.

What am I trying to do? I really don't know! :wink:

There is one switch. If you hold it down for X seconds it switch the Preset Mosfet "on". Hold it for X seconds again it turns the Preset Mosfet "off".

Now if you tap the switch multiple times for shorter than X seconds it sends a tap tempo signal to the Tap Mosfet.

I'm trying to read up on this but it's going to take a while to understand it all. Hoping someone could help me get this going and explain it a little to me. I'm not 100% sure what to tell you. I can supply a schematic if that helps at all. I was going to simply change all the bytes to boolean but I really didn't know if that was going to fix anything or make the circuit not work properly. I'd rather try and understand it rather than just changing stuff at random.

Edit: Changing all the byte to boolean does remove the error when verifying. I suppose I should just try it and see what happens.
/Actuates the Preset MOSFET
void doublePreset(boolean actuator, boolean indicator1, boolean indicator2, boolean holdState, boolean *lastHoldState){

If the value can only be 0 or 1 (false or true) make it a boolean. If the value can be in the range 0 to 255, make it a byte.

I think in this case you have a flag that is either true or false so the function argument should be "boolean *lastHoldState" instead of "byte *lastHoldState".

The other arguments should be 'byte' or 'boolean' depending on what values can be passed to them.

There really isn't any reason to pass a pointer to 'lastHoldState'. It's already a global variable, and the pointer is dereferenced in every singe use in the function. A simple reference to it would make the whole thing much easier.

johnwasser:
If the value can only be 0 or 1 (false or true) make it a boolean. If the value can be in the range 0 to 255, make it a byte.

I think in this case you have a flag that is either true or false so the function argument should be "boolean *lastHoldState" instead of "byte *lastHoldState".

The other arguments should be 'byte' or 'boolean' depending on what values can be passed to them.

Thank you. That explained a lot. I'll give it a go and see what happens.

aarg:
There really isn't any reason to pass a pointer to 'lastHoldState'. It's already a global variable, and the pointer is dereferenced in every singe use in the function. A simple reference to it would make the whole thing much easier.

Thanks, I'll look into that.

There are probably dozens of simplifications that would be beneficial. No way should any run of the mill function have 9 parameters.

aarg:
There are probably dozens of simplifications that would be beneficial. No way should any run of the mill function have 9 parameters.

Like I said, I'm just starting to learn so cleaning things up to simplify them isn't probably going to happen. At least for a while but thank you. I'll keep it in mind.

Can you point out what you are referring to though? I'd like to take a look at it.

Where you find yourself needing more than about four parameters, it’s time to think about some structures or a class to hold them.

If your dead certain the code will be reusable elsewhere, make it a class.

If not, and when you’re only using the function once (i.e. when there isn’t even any possibility of internal code reuse), then there’s no point in passing in a whole heap of globals as parameters when you could have just referenced the globals directly.