Hackster will be offline on Monday, June 15 from 5pm to 7pm PDT to perform some scheduled maintenance.
Patrick Fitzgerald
Published © GPL3+

Pragma Directive Optimize Arduino Sketch

Arduino IDE defaults to optimize your code for size. It removes no operation commands and changes the instructions you put in.

BeginnerProtip1 hour278
Pragma Directive Optimize Arduino Sketch

Things used in this project

Story

Read more

Code

pragma.ino

Arduino
Arduino sketch with pragma to turn optimization off
binary count on PORTB nop delay
// pragma directive O0 tells compiler no optimization, default Os for size
#pragma GCC optimize ("-O0") // letter o then zero
#include <avr/io.h>
int main(void){ DDRB = 0xFF; // turn PORTB pins on
  while(1) { PORTB++;
    {for (long i=0 ; i<0x7FFF ; i++) {;}}}}

Credits

Patrick Fitzgerald
134 projects • 61 followers

Comments