Using real C

So I just got my Arduino and successfully got the blinking light sketch to work. Then I pasted a program from a book I’m learning from and it goes as follows

#include <avr/io.h>
#include <util/delay.h>

int main(void) {

while(1) {
PORTB = 0x20;
PORTB = 0x00;
return 1;

it should do the same thing but for some reason it only blinks once and then a some lights blink really quickly under my Ethernet shield. Are these error lights? Why wont this functional program work? I’m using the MEGA 2560 if that changes anything.
Thanks guys for reading this any help is appreciated once i get past this speed bump I look forward to contributing to the community ASAP.

Welcome to the forum. Recommend you take a look at this before going any further.

The Arduino IDE uses "real" C/C++. However it gives you a helping hand by providing some of the boilerplate (such as the main() function) in the background.


Direct port manipulation (which is what PINB is doing) is NOT portable code. It was designed for ONE Arduino model. If you try to run that on a different model, it may, or may not, actually work.

Which Arduino was that code actually written for?

Doing direct port manipulation, because it is faster than digitalWrite(), and then delaying, in any fashion, is just plain stupid.