Why is my led not blinking with this code

#define MYPORTB (volatile byte*)0x25
#define MYDDRB (volatile byte*)0x24

int main(void)
{
  *MYDDRB = 0b100000;
  while(1)
  {
    *MYPORTB = 0b100000;
    delay(1000);
    *MYPORTB = 0b0;
    delay(1000);
  }
}

why is my led is not blinking but is rather constantly on ?

How does delay work?

What happens when you change this to:

*MYPORTB = 0b10000000;

You can't use any Arduino features like 'delay()' if you don't initialize the library by calling init() at the beginning of 'main()'.

(If you use normal Arduino format, the built-in main() will call init() before calling your setup().)

1 Like

Im using vscode with platform.io and #include <Arduino.h> so i should call init at the start of my main function

Yes.
In which case, you might as well just use pinMode/digitalWrite

When you start a new project in PlatformIO, it gives you a choice of board. Then, it will usually pre-select Arduino framework.
The new project that is created has setup() and loop() functions in it already.
Using the main() function perhaps confused it. You normally don't need to #include avr.h

I just tested your program but put the

in setup().

The rest of the code should be in loop. Of course, you won't need the while(), since loop will do that for you.
Led blinks :slight_smile:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.