Converting to a nano every

I dont understand why some code works with both Arduino nano and the nano every but I'm trying to get a ppm generator to work with the nano every and it just does not like that sketch whatsoever. It doesn't like "digitalWrite(sigPin, !onState);"

changed it to digitalWrite(sigPin, 0);

All of the variables need declaring and it doesn't like "|=" . Why is there such a change in the code format for this board.

The reason this is no longer supported is that Arduino made a change in the type of the pin state parameter of digitalWrite() from uint8_t to PinStatus.

Here is the signature of the function when you are compiling for your classic Nano:

void digitalWrite(uint8_t pin, uint8_t val);

Here is the signature of the function when you are compiling for the Nano Every (as well as the Nano 33 BLE or Portenta H7):

http://void digitalWrite(pin_size_t pinNumber, PinStatus status);

The thing is, it was never really appropriate to treat the pin state as a boolean. It used to work because the pin states happened to be defined as 0 and 1, but there was never any guarantee of this. However, there is quite a bit of code like the sketch you have that made this assumption. For that reason, I made a request for Arduino to investigate this issue:

Arduino's developers have identified a fix for the issue and it's likely the next release of the Arduino megaAVR Boards platform of the Nano Every will have this fix.

I think that in this case, the easiest correct (as opposed to assuming 0 == LOW) way to fix your code would be to define an offState variable in addition to the onState:

const PinStatus onState=HIGH;
const PinStatus offState=LOW;

...

digitalWrite(sigPin, offState);

it was never really appropriate to treat the pin state as a boolean.

It certainly did, for output! Digital outputs have two states; 0 and 1. It matches exactly with the lower level hardware. And "output" is implied by digitalWrite()

It's not like they changed digitalWrite() to allow the additional enum values to do anything meaningful.
If they want to add a new function "pinState()", IT can accept the enum. Messing with digitalWrite() was a horrible idea. (Of course, it wasn't a great idea to have HIGH and LOW symbols separate from true/false or 1/0 in the first place, but at least that has HISTORY behind it now.)

Yeah however changing the digitalwrite to an appropriate state still doesn't allow the program to work. It seems like there's more than just that. Something tells me it has a problem compiling the math portion on it.. like the ! in front of the onstate. The other digital write for the onstate doesn't have a problem. Being defined as 1 and not HIGH.

once those are fixed it asked to declare all the variables. If I throw 'int' in front of all the variable it then has a problem with "|=" .. So I dont know if compiler is giving me the wrong news and I'm chasing something random.

If you haven't figured it out I'm not a solid coder. My knowledge is good enough to splice programs together and create easier thing but when it comes to core issues like this I'm way outa my league.

Here's the code from the link @Fallegon posted above:

/*
 * PPM generator originally written by David Hasko
 * on https://code.google.com/p/generate-ppm-signal/ 
 */

//////////////////////CONFIGURATION///////////////////////////////
#define CHANNEL_NUMBER 12  //set the number of chanels
#define CHANNEL_DEFAULT_VALUE 1500  //set the default servo value
#define FRAME_LENGTH 22500  //set the PPM frame length in microseconds (1ms = 1000µs)
#define PULSE_LENGTH 300  //set the pulse length
#define onState 1  //set polarity of the pulses: 1 is positive, 0 is negative
#define sigPin 10  //set PPM signal output pin on the arduino

/*this array holds the servo values for the ppm signal
 change theese values in your code (usually servo values move between 1000 and 2000)*/
int ppm[CHANNEL_NUMBER];

void setup(){  

  //initiallize default ppm values
  for(int i=0; i<CHANNEL_NUMBER; i++){
      ppm[i]= CHANNEL_DEFAULT_VALUE;
  }

  pinMode(sigPin, OUTPUT);
  digitalWrite(sigPin, !onState);  //set the PPM signal pin to the default state (off)
  
  cli();
  TCCR1A = 0; // set entire TCCR1 register to 0
  TCCR1B = 0;
  
  OCR1A = 100;  // compare match register, change this
  TCCR1B |= (1 << WGM12);  // turn on CTC mode
  TCCR1B |= (1 << CS11);  // 8 prescaler: 0,5 microseconds at 16mhz
  TIMSK1 |= (1 << OCIE1A); // enable timer compare interrupt
  sei();

}

void loop(){
  
  /*
    Here modify ppm array and set any channel to value between 1000 and 2000. 
    Timer running in the background will take care of the rest and automatically 
    generate PPM signal on output pin using values in ppm array
  */
  
}

ISR(TIMER1_COMPA_vect){  //leave this alone
  static boolean state = true;
  
  TCNT1 = 0;
  
  if (state) {  //start pulse
    digitalWrite(sigPin, onState);
    OCR1A = PULSE_LENGTH * 2;
    state = false;
  } else{  //end pulse and calculate when to start the next pulse
    static byte cur_chan_numb;
    static unsigned int calc_rest;
  
    digitalWrite(sigPin, !onState);
    state = true;

    if(cur_chan_numb >= CHANNEL_NUMBER){
      cur_chan_numb = 0;
      calc_rest = calc_rest + PULSE_LENGTH;// 
      OCR1A = (FRAME_LENGTH - calc_rest) * 2;
      calc_rest = 0;
    }
    else{
      OCR1A = (ppm[cur_chan_numb] - PULSE_LENGTH) * 2;
      calc_rest = calc_rest + ppm[cur_chan_numb];
      cur_chan_numb++;
    }     
  }
}

So the reason you're getting those "was not declared in this scope" errors when compiling for the Nano Every is because this code is very architecture-specific. Despite the similar names, the Nano Every has significant differences from the classic Nano. You won't notice that often when using the standardized core Arduino API functions like digitalWrite(), but low level code like this sketch is not portable to other architectures, or even many of the other processors of the same AVR architecture that don't have these registers.

You'll never fix it by declaring variables to replace the missing register names. You would need to gain an in depth understanding of low level programming for the Nano Every's ATmega4809 microcontroller, then porting the code over to that architecture.

Ok I understand now. I found some nano every references about this but understanding it is a whole different thing. I didn't realize that it was code specifically for the nano processor. The only reason why I switched to a nano every was because my sketch was too big. Big bummer. I guess I'll try to make the changes.