As no preview is available at the given links (for YMFC-AL_setup.ino and YMFC-AL_Flight_controller.ino at drive.google.com) and I don't want to download the code to my system, I haven't looked at the whole program; however, from the code included in the question, it's clear that it uses direct IO rather than Arduino API IO.
Direct IO expressions like PINB & B00000001
affect differently-numbered digital pins on the Mega than on the Uno or Nano. (Or, more generally, on boards based on ATmega256x vs ATmega328x or 168x vs ATmega32U4 or 16U4.)
On the Arduino Nano and Uno, PB0–PB5 are assigned to Arduino digital pins 8–13.
On the Arduino Micro with 32U4, PB0–PB3 are not assigned to Arduino digital pins; they connect to SS, SCK, MOSI, MISO, while PB4–PB7 are assigned to Arduino digital pins 8–11.
On the Arduino Mega2560 with ATmega2560, PB0–PB3 are assigned to Arduino digital pins 53, 52, 51, 50 respectively, and PB4–PB7 are assigned to 10–13.
Summary: To adapt direct IO code written for an Uno to a Mega, you may need to change ports and pins numbers. Just moving wires around to corresponding pins may or may not fix problems; if the code uses a mix of direct IO and API IO (with digitalWrite()
etc.) the code may need to be changed as well. For example, in setup()
it might use API pin identifiers, and in ISRs might use direct IO, an approach that will malfunction when transferring code to a differently-mapped board.
Note, see numerous excellent pinout diagrams at pighixxx.com.
- 8.9k
- 3
- 20
- 33