Digital Outputs

Graynomad:
How do you know it's not working, you can't see that frequency.

Also it may not be possible to get exactly 1.2Mhz and using a loop the waveform won't be a 50% duty cycle. Does any of that matter to your application?

EDIT: On the 2560 pin 4 is PORTG bit 5. You are using PORTD bit 4 which is not connected to anything on the Mega.

Try PORTB bit 7 for the LED, but as I said at that speed you need instruments to see it.

Try

void setup()

{
  pinMode(13, OUTPUT);      // sets the digital pin as output
}

void loop()
{
  PORTB = B10000000;
  PORTB = B00000000;
  delay (1000);
}




To verify that the LED is blinking.

______
Rob

Awesome, that totally works! Using your sample code, and getting rid of that delay(1000), I was able to get a 934kHz signal, which is usable.

My only question now is that this is done by NOT using ANY other commands. I'm using my microcontroller to read in a signal and perform some calculations on it and output it to a serial, as well as creating this signal. Once I introduce those other commands, it's going to slow this signal down right? Is there any way around that, or is my knowledge of arduino code just too basic?