Using Arduino Nano Every instead of Arduino Nano at an acustic levitation project

Hello All,
I wanted to make a fun project based on instructables acustic levitator however, I bought Arduino Nano Every instead of Arduino Nano. I'm not very well versed in coding, and when I tried adding the code in the guide:

#include <avr/io.h>
#include <avr/interrupt.h>

#define N_PORTS 1
#define N_DIVS 24

#define WAIT_LOT() __asm__ __volatile__("nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t")
#define WAIT_MID() __asm__ __volatile__("nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t")
#define WAIT_LIT() __asm__ __volatile__("nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t" \
                                        "nop\n\t")

#define OUTPUT_WAVE(pointer, d) PORTC = pointer[d * N_PORTS]

#define N_BUTTONS 6
#define STEP_SIZE 1
#define BUTTON_SENS 2500
#define N_FRAMES 24

volatile byte frame = 0;
static byte animation[N_FRAMES][N_DIVS] = { { 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa },
                                            { 0x9, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x6, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa },
                                            { 0x9, 0x9, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x6, 0x6, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa },
                                            { 0x9, 0x9, 0x9, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x6, 0x6, 0x6, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa },
                                            { 0x9, 0x9, 0x9, 0x9, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x6, 0x6, 0x6, 0x6, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa },
                                            { 0x9, 0x9, 0x9, 0x9, 0x9, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x6, 0x6, 0x6, 0x6, 0x6, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa },
                                            { 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa },
                                            { 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x5, 0x5, 0x5, 0x5, 0x5, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0xa, 0xa, 0xa, 0xa, 0xa },
                                            { 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x5, 0x5, 0x5, 0x5, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0xa, 0xa, 0xa, 0xa },
                                            { 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x5, 0x5, 0x5, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0xa, 0xa, 0xa },
                                            { 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x5, 0x5, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0xa, 0xa },
                                            { 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x5, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0xa },
                                            { 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6 },
                                            { 0x5, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0xa, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6 },
                                            { 0x5, 0x5, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0xa, 0xa, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6 },
                                            { 0x5, 0x5, 0x5, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0xa, 0xa, 0xa, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6 },
                                            { 0x5, 0x5, 0x5, 0x5, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0xa, 0xa, 0xa, 0xa, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6 },
                                            { 0x5, 0x5, 0x5, 0x5, 0x5, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0xa, 0xa, 0xa, 0xa, 0xa, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6 },
                                            { 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x9, 0x9, 0x9, 0x9, 0x9, 0x9, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0x6, 0x6, 0x6, 0x6, 0x6, 0x6 },
                                            { 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x9, 0x9, 0x9, 0x9, 0x9, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0x6, 0x6, 0x6, 0x6, 0x6 },
                                            { 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x9, 0x9, 0x9, 0x9, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0x6, 0x6, 0x6, 0x6 },
                                            { 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x9, 0x9, 0x9, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0x6, 0x6, 0x6 },
                                            { 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x9, 0x9, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0x6, 0x6 },
                                            { 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x5, 0x9, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0xa, 0x6 } };


void setup() {

  /*
 for (int i = 0; i < (N_PORTS*N_DIVS); ++i){
    animation[frame][i] =  0;
  }

  for (int i = 0; i < (N_PORTS*N_DIVS/2); ++i){
     animation[frame][i] = 0b11111111;
  }
  
  for(int i = 0; i < N_DIVS; ++i){
    if (i % 2 == 0){
      animation[frame][i * N_PORTS] |= 0b00000001;
    }else{
      animation[frame][i * N_PORTS] &= 0b11111110;
    }
  }
*/
  DDRC = 0b00001111;  //A0 to A3 are the signal outputs
  PORTC = 0b00000000;

  pinMode(10, OUTPUT);        //pin 10 (B2) will generate a 40kHz signal to sync
  pinMode(11, INPUT_PULLUP);  //pin 11 (B3) is the sync in
  //please connect pin 10 to pin 11

  for (int i = 2; i < 8; ++i) {  //pin 2 to 7 (D2 to D7) are inputs for the buttons
    pinMode(i, INPUT_PULLUP);
  }

  // generate a sync signal of 40khz in pin 10
  noInterrupts();                           // disable all interrupts
  TCA0.SINGLE.CTRLA = TC_CLKSEL_DIV1_gc;    // Set clock source to CLK_PER (no prescaling)
  TCA0.SINGLE.CTRLB = TC_WGMODE_NORMAL_gc;  // Normal waveform generation mode
  TCA0.SINGLE.PER = (F_CPU / 40000L) - 1;   // Set period
  TCA0.SINGLE.CMPB = (F_CPU / 40000L) / 2;  // Set compare B value
  interrupts();                             // enable all interrupts

  // disable everything that we do not need
  ADC0.CTRLA = 0;  // Disable ADC
  power_adc_disable();
  power_spi_disable();
  power_twi0_disable();  // For TWI (I2C), if used
  power_timer0_disable();

  //power_usart0_disable();
  Serial.begin(115200);

  byte* emittingPointer = &animation[frame][0];
  byte buttonsPort = 0;

  bool anyButtonPressed;
  bool buttonPressed[N_BUTTONS];
  short buttonCounter = 0;

LOOP:
  while (PINB & 0b00001000)
    ;  //wait for pin 11 (B3) to go low

  OUTPUT_WAVE(emittingPointer, 0);
  buttonsPort = PIND;
  WAIT_LIT();
  OUTPUT_WAVE(emittingPointer, 1);
  anyButtonPressed = (buttonsPort & 0b11111100) != 0b11111100;
  WAIT_MID();
  OUTPUT_WAVE(emittingPointer, 2);
  buttonPressed[0] = buttonsPort & 0b00000100;
  WAIT_MID();
  OUTPUT_WAVE(emittingPointer, 3);
  buttonPressed[1] = buttonsPort & 0b00001000;
  WAIT_MID();
  OUTPUT_WAVE(emittingPointer, 4);
  buttonPressed[2] = buttonsPort & 0b00010000;
  WAIT_MID();
  OUTPUT_WAVE(emittingPointer, 5);
  buttonPressed[3] = buttonsPort & 0b00100000;
  WAIT_MID();
  OUTPUT_WAVE(emittingPointer, 6);
  buttonPressed[4] = buttonsPort & 0b01000000;
  WAIT_MID();
  OUTPUT_WAVE(emittingPointer, 7);
  buttonPressed[5] = buttonsPort & 0b10000000;
  WAIT_MID();
  OUTPUT_WAVE(emittingPointer, 8);
  WAIT_LOT();
  OUTPUT_WAVE(emittingPointer, 9);
  WAIT_LOT();
  OUTPUT_WAVE(emittingPointer, 10);
  WAIT_LOT();
  OUTPUT_WAVE(emittingPointer, 11);
  WAIT_LOT();
  OUTPUT_WAVE(emittingPointer, 12);
  WAIT_LOT();
  OUTPUT_WAVE(emittingPointer, 13);
  WAIT_LOT();
  OUTPUT_WAVE(emittingPointer, 14);
  WAIT_LOT();
  OUTPUT_WAVE(emittingPointer, 15);
  WAIT_LOT();
  OUTPUT_WAVE(emittingPointer, 16);
  WAIT_LOT();
  OUTPUT_WAVE(emittingPointer, 17);
  WAIT_LOT();
  OUTPUT_WAVE(emittingPointer, 18);
  WAIT_LOT();
  OUTPUT_WAVE(emittingPointer, 19);
  WAIT_LOT();
  OUTPUT_WAVE(emittingPointer, 20);
  WAIT_LOT();
  OUTPUT_WAVE(emittingPointer, 21);
  WAIT_LOT();
  OUTPUT_WAVE(emittingPointer, 22);
  WAIT_LOT();
  OUTPUT_WAVE(emittingPointer, 23);


  if (anyButtonPressed) {
    ++buttonCounter;
    if (buttonCounter > BUTTON_SENS) {
      buttonCounter = 0;

      if (!buttonPressed[0]) {
        if (frame < STEP_SIZE) {
          frame = N_FRAMES - 1;
        } else {
          frame -= STEP_SIZE;
        }
      } else if (!buttonPressed[1]) {
        if (frame >= N_FRAMES - STEP_SIZE) {
          frame = 0;
        } else {
          frame += STEP_SIZE;
        }
      } else if (!buttonPressed[2]) {
        frame = 0;
      }
      emittingPointer = &animation[frame][0];
    }
  } else {
    buttonCounter = 0;
  }

  goto LOOP;
}

void loop() {}

I got a lot of errors:

C:\fun\2023\levitation\FFWIH82J98RXO3E\Nano_TinyLev\Nano_TinyLev.ino: In function 'void setup()':
C:\fun\2023\levitation\FFWIH82J98RXO3E\Nano_TinyLev\Nano_TinyLev.ino:113:23: error: 'TC_CLKSEL_DIV1_gc' was not declared in this scope
   TCA0.SINGLE.CTRLA = TC_CLKSEL_DIV1_gc;    // Set clock source to CLK_PER (no prescaling)
                       ^~~~~~~~~~~~~~~~~
C:\fun\2023\levitation\FFWIH82J98RXO3E\Nano_TinyLev\Nano_TinyLev.ino:113:23: note: suggested alternative: 'TCB_CLKSEL_CLKDIV1_gc'
   TCA0.SINGLE.CTRLA = TC_CLKSEL_DIV1_gc;    // Set clock source to CLK_PER (no prescaling)
                       ^~~~~~~~~~~~~~~~~
                       TCB_CLKSEL_CLKDIV1_gc
C:\fun\2023\levitation\FFWIH82J98RXO3E\Nano_TinyLev\Nano_TinyLev.ino:114:23: error: 'TC_WGMODE_NORMAL_gc' was not declared in this scope
   TCA0.SINGLE.CTRLB = TC_WGMODE_NORMAL_gc;  // Normal waveform generation mode
                       ^~~~~~~~~~~~~~~~~~~
C:\fun\2023\levitation\FFWIH82J98RXO3E\Nano_TinyLev\Nano_TinyLev.ino:114:23: note: suggested alternative: 'USART_RXMODE_NORMAL_gc'
   TCA0.SINGLE.CTRLB = TC_WGMODE_NORMAL_gc;  // Normal waveform generation mode
                       ^~~~~~~~~~~~~~~~~~~
                       USART_RXMODE_NORMAL_gc
C:\fun\2023\levitation\FFWIH82J98RXO3E\Nano_TinyLev\Nano_TinyLev.ino:116:15: error: 'TCA_SINGLE_t {aka struct TCA_SINGLE_struct}' has no member named 'CMPB'
   TCA0.SINGLE.CMPB = (F_CPU / 40000L) / 2;  // Set compare B value
               ^~~~
C:\fun\2023\levitation\FFWIH82J98RXO3E\Nano_TinyLev\Nano_TinyLev.ino:121:3: error: 'power_adc_disable' was not declared in this scope
   power_adc_disable();
   ^~~~~~~~~~~~~~~~~
C:\fun\2023\levitation\FFWIH82J98RXO3E\Nano_TinyLev\Nano_TinyLev.ino:122:3: error: 'power_spi_disable' was not declared in this scope
   power_spi_disable();
   ^~~~~~~~~~~~~~~~~
C:\fun\2023\levitation\FFWIH82J98RXO3E\Nano_TinyLev\Nano_TinyLev.ino:123:3: error: 'power_twi0_disable' was not declared in this scope
   power_twi0_disable();  // For TWI (I2C), if used
   ^~~~~~~~~~~~~~~~~~
C:\fun\2023\levitation\FFWIH82J98RXO3E\Nano_TinyLev\Nano_TinyLev.ino:124:3: error: 'power_timer0_disable' was not declared in this scope
   power_timer0_disable();
   ^~~~~~~~~~~~~~~~~~~~
C:\fun\2023\levitation\FFWIH82J98RXO3E\Nano_TinyLev\Nano_TinyLev.ino:137:10: error: 'PINB' was not declared in this scope
   while (PINB & 0b00001000)
          ^~~~
C:\fun\2023\levitation\FFWIH82J98RXO3E\Nano_TinyLev\Nano_TinyLev.ino:137:10: note: suggested alternative: 'PIN0'
   while (PINB & 0b00001000)
          ^~~~
          PIN0
C:\fun\2023\levitation\FFWIH82J98RXO3E\Nano_TinyLev\Nano_TinyLev.ino:141:17: error: 'PIND' was not declared in this scope
   buttonsPort = PIND;
                 ^~~~
C:\fun\2023\levitation\FFWIH82J98RXO3E\Nano_TinyLev\Nano_TinyLev.ino:141:17: note: suggested alternative: 'PIN0'
   buttonsPort = PIND;
                 ^~~~
                 PIN0

exit status 1

Compilation error: 'TC_CLKSEL_DIV1_gc' was not declared in this scope

Can I somehow salvage the situation with the Arduino Nano Every or should I just buy a separate Arduino Nano?

Thanks very much in advance for all your help!

The latter will be easier.

You should be able to make this work with the Every, too. The author of the sketch quite extensively used direct register programming to get certain things done (e.g. generate a 40kHz waveform) on the ATMega328 chip used on the regular Nano. There are equivalents for these actions on the ATMega4809 used on the Every, but you'll have to root around the datasheets of both chips to 'translate' the sketch to the Every hardware. Given this:

...I'd just get a Nano instead and get going with the project.

2 Likes

If I select that the board on Arduino IDE is the Nano, I still get very similar compile error.

C:\Work\2023\levitation\FFWIH82J98RXO3E\Nano_TinyLev\Nano_TinyLev.ino: In function 'void setup()':
C:\Work\2023\levitation\FFWIH82J98RXO3E\Nano_TinyLev\Nano_TinyLev.ino:113:3: error: 'TCA0' was not declared in this scope
   TCA0.SINGLE.CTRLA = TC_CLKSEL_DIV1_gc;    // Set clock source to CLK_PER (no prescaling)
   ^~~~
C:\Work\2023\levitation\FFWIH82J98RXO3E\Nano_TinyLev\Nano_TinyLev.ino:113:3: note: suggested alternative: 'TWA0'
   TCA0.SINGLE.CTRLA = TC_CLKSEL_DIV1_gc;    // Set clock source to CLK_PER (no prescaling)
   ^~~~
   TWA0
C:\Work\2023\levitation\FFWIH82J98RXO3E\Nano_TinyLev\Nano_TinyLev.ino:113:23: error: 'TC_CLKSEL_DIV1_gc' was not declared in this scope
   TCA0.SINGLE.CTRLA = TC_CLKSEL_DIV1_gc;    // Set clock source to CLK_PER (no prescaling)
                       ^~~~~~~~~~~~~~~~~
C:\Work\2023\levitation\FFWIH82J98RXO3E\Nano_TinyLev\Nano_TinyLev.ino:114:23: error: 'TC_WGMODE_NORMAL_gc' was not declared in this scope
   TCA0.SINGLE.CTRLB = TC_WGMODE_NORMAL_gc;  // Normal waveform generation mode
                       ^~~~~~~~~~~~~~~~~~~
C:\Work\2023\levitation\FFWIH82J98RXO3E\Nano_TinyLev\Nano_TinyLev.ino:120:3: error: 'ADC0' was not declared in this scope
   ADC0.CTRLA = 0;  // Disable ADC
   ^~~~
C:\Work\2023\levitation\FFWIH82J98RXO3E\Nano_TinyLev\Nano_TinyLev.ino:120:3: note: suggested alternative: 'ADCH'
   ADC0.CTRLA = 0;  // Disable ADC
   ^~~~
   ADCH
C:\Work\2023\levitation\FFWIH82J98RXO3E\Nano_TinyLev\Nano_TinyLev.ino:121:3: error: 'power_adc_disable' was not declared in this scope
   power_adc_disable();
   ^~~~~~~~~~~~~~~~~
C:\Work\2023\levitation\FFWIH82J98RXO3E\Nano_TinyLev\Nano_TinyLev.ino:122:3: error: 'power_spi_disable' was not declared in this scope
   power_spi_disable();
   ^~~~~~~~~~~~~~~~~
C:\Work\2023\levitation\FFWIH82J98RXO3E\Nano_TinyLev\Nano_TinyLev.ino:123:3: error: 'power_twi0_disable' was not declared in this scope
   power_twi0_disable();  // For TWI (I2C), if used
   ^~~~~~~~~~~~~~~~~~
C:\Work\2023\levitation\FFWIH82J98RXO3E\Nano_TinyLev\Nano_TinyLev.ino:124:3: error: 'power_timer0_disable' was not declared in this scope
   power_timer0_disable();
   ^~~~~~~~~~~~~~~~~~~~

exit status 1

Compilation error: 'TCA0' was not declared in this scope

What am I doing wrong?

I don't know; I downloaded the code from the Instructables and compiled it for Arduino Nano without errors. This is the code I downloaded:

#include <avr/sleep.h>
#include <avr/power.h>

#define N_PORTS 1
#define N_DIVS 24

#define WAIT_LOT(a) __asm__ __volatile__ ("nop"); __asm__ __volatile__ ("nop"); __asm__ __volatile__ ("nop");  __asm__ __volatile__ ("nop"); __asm__ __volatile__ ("nop");__asm__ __volatile__ ("nop"); __asm__ __volatile__ ("nop");__asm__ __volatile__ ("nop"); __asm__ __volatile__ ("nop");  __asm__ __volatile__ ("nop"); __asm__ __volatile__ ("nop");__asm__ __volatile__ ("nop");  __asm__ __volatile__ ("nop");  __asm__ __volatile__ ("nop")
#define WAIT_MID(a) __asm__ __volatile__ ("nop"); __asm__ __volatile__ ("nop"); __asm__ __volatile__ ("nop");  __asm__ __volatile__ ("nop"); __asm__ __volatile__ ("nop");__asm__ __volatile__ ("nop"); __asm__ __volatile__ ("nop");__asm__ __volatile__ ("nop"); __asm__ __volatile__ ("nop"); __asm__ __volatile__ ("nop"); __asm__ __volatile__ ("nop"); __asm__ __volatile__ ("nop"); __asm__ __volatile__ ("nop")
#define WAIT_LIT(a) __asm__ __volatile__ ("nop"); __asm__ __volatile__ ("nop"); __asm__ __volatile__ ("nop");  __asm__ __volatile__ ("nop"); __asm__ __volatile__ ("nop");  __asm__ __volatile__ ("nop");  __asm__ __volatile__ ("nop");  __asm__ __volatile__ ("nop");  __asm__ __volatile__ ("nop")


#define OUTPUT_WAVE(pointer, d)  PORTC = pointer[d*N_PORTS + 0]

#define N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6},
{0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x9,0x9,0x9,0x9,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0x6,0x6,0x6,0x6},
{0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x9,0x9,0x9,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0x6,0x6,0x6},
{0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x9,0x9,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0x6,0x6},
{0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x5,0x9,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0xa,0x6}};


void setup()
{

/*
 for (int i = 0; i < (N_PORTS*N_DIVS); ++i){
    animation[frame][i] =  0;
  }

  for (int i = 0; i < (N_PORTS*N_DIVS/2); ++i){
     animation[frame][i] = 0b11111111;
  }
  
  for(int i = 0; i < N_DIVS; ++i){
    if (i % 2 == 0){
      animation[frame][i * N_PORTS] |= 0b00000001;
    }else{
      animation[frame][i * N_PORTS] &= 0b11111110;
    }
  }
*/
   DDRC = 0b00001111; //A0 to A3 are the signal outputs
   PORTC = 0b00000000; 
   
   pinMode(10, OUTPUT); //pin 10 (B2) will generate a 40kHz signal to sync 
   pinMode(11, INPUT_PULLUP); //pin 11 (B3) is the sync in
   //please connect pin 10 to pin 11

   for (int i = 2; i < 8; ++i){ //pin 2 to 7 (D2 to D7) are inputs for the buttons
    pinMode(i, INPUT_PULLUP); 
   }

  // generate a sync signal of 40khz in pin 10
  noInterrupts();           // disable all interrupts
  TCCR1A = bit (WGM10) | bit (WGM11) | bit (COM1B1); // fast PWM, clear OC1B on compare
  TCCR1B = bit (WGM12) | bit (WGM13) | bit (CS10);   // fast PWM, no prescaler
  OCR1A =  (F_CPU / 40000L) - 1;
  OCR1B = (F_CPU / 40000L) / 2;
  interrupts();             // enable all interrupts

  // disable everything that we do not need 
  ADCSRA = 0;  // ADC
  power_adc_disable ();
  power_spi_disable();
  power_twi_disable();
  power_timer0_disable();
  //power_usart0_disable();
  Serial.begin(115200);

 byte* emittingPointer = &animation[frame][0];
 byte buttonsPort = 0;

 bool anyButtonPressed;
 bool buttonPressed[N_BUTTONS];
 short buttonCounter = 0;

  LOOP:
    while(PINB & 0b00001000); //wait for pin 11 (B3) to go low 
    
    OUTPUT_WAVE(emittingPointer, 0); buttonsPort = PIND; WAIT_LIT();
    OUTPUT_WAVE(emittingPointer, 1); anyButtonPressed = (buttonsPort & 0b11111100) != 0b11111100; WAIT_MID();
    OUTPUT_WAVE(emittingPointer, 2); buttonPressed[0] = buttonsPort & 0b00000100; WAIT_MID();
    OUTPUT_WAVE(emittingPointer, 3); buttonPressed[1] = buttonsPort & 0b00001000; WAIT_MID();
    OUTPUT_WAVE(emittingPointer, 4); buttonPressed[2] = buttonsPort & 0b00010000; WAIT_MID();
    OUTPUT_WAVE(emittingPointer, 5); buttonPressed[3] = buttonsPort & 0b00100000; WAIT_MID();
    OUTPUT_WAVE(emittingPointer, 6); buttonPressed[4] = buttonsPort & 0b01000000; WAIT_MID();
    OUTPUT_WAVE(emittingPointer, 7); buttonPressed[5] = buttonsPort & 0b10000000; WAIT_MID();
    OUTPUT_WAVE(emittingPointer, 8); WAIT_LOT();
    OUTPUT_WAVE(emittingPointer, 9); WAIT_LOT();
    OUTPUT_WAVE(emittingPointer, 10); WAIT_LOT();
    OUTPUT_WAVE(emittingPointer, 11); WAIT_LOT();
    OUTPUT_WAVE(emittingPointer, 12); WAIT_LOT();
    OUTPUT_WAVE(emittingPointer, 13); WAIT_LOT();
    OUTPUT_WAVE(emittingPointer, 14); WAIT_LOT();
    OUTPUT_WAVE(emittingPointer, 15); WAIT_LOT();
    OUTPUT_WAVE(emittingPointer, 16); WAIT_LOT();
    OUTPUT_WAVE(emittingPointer, 17); WAIT_LOT();
    OUTPUT_WAVE(emittingPointer, 18); WAIT_LOT();
    OUTPUT_WAVE(emittingPointer, 19); WAIT_LOT();
    OUTPUT_WAVE(emittingPointer, 20); WAIT_LOT();
    OUTPUT_WAVE(emittingPointer, 21); WAIT_LOT();
    OUTPUT_WAVE(emittingPointer, 22); WAIT_LOT();
    OUTPUT_WAVE(emittingPointer, 23); 


    if( anyButtonPressed ){
       ++buttonCounter;
       if (buttonCounter > BUTTON_SENS){
        buttonCounter = 0;
        
        if (! buttonPressed[0] ) {
          if( frame < STEP_SIZE ) { 
            frame = N_FRAMES-1;
         }else{
            frame-=STEP_SIZE; 
         }
        }
        else if (! buttonPressed[1] ) { 
          if ( frame >= N_FRAMES-STEP_SIZE ) { 
            frame = 0;
          }else {
            frame+=STEP_SIZE; 
          }  
       }else if (! buttonPressed[2] ) { 
          frame = 0;
       }
        emittingPointer = & animation[frame][0];
       }
    }else {
      buttonCounter = 0;
    }
    
  goto LOOP;
  
}

void loop(){}

It's different from the code you posted in #1. I don't know where you got that code. I got the code in my post from step 13 in the page you linked to.

Instructions like these are not valid on the "classic" Nano, or any ATmega328-based processor. They might be for the Nano Every.

If you inform the compiler that it is to compile for the classic Nano, it will flag such errors.

Some googling suggests they might work for the XMEGA D3 series. I don't think any of those found their way onto an Arduino board, but who knows!?

@dzsingiszke did you feed the code from Instructables into ChatGPT or something? That would explain the hodgepodge you ended up with.

Yes, I tried asking ChatGPT if it can make it work to my Arduino Nano Every, but to no avail. Damn I forgot that so easily. :smiley:
Anyway the code works, now I just need to order an Arduino Nano :slight_smile:

No, AI has many merits, but it's not too good at making code yet. Since it has no awareness as such, "it" basically doesn't "realize" that the register mapping for an Every (Mega4809) is really different for another controller.

Artificial Intelligence is a misnomer, really. It's not really intelligent. It's just reasonably good at spotting patterns. It just can't understand/interpret these patterns.