// Demonstration sketch that uses the whole 8-bits PORT of a ATmega328P at once.
//
// Arduino Uno pin mapping:
// https://www.arduino.cc/en/Hacking/PinMapping168
//
// PortB:
// PB0 to PB7, but PB6 and BP7 are connected to the crystal.
// If the crystal is used, PB6 and PB7 are not connected and ignored.
// That means that for the Arduino Uno, the whole port can be written
// and PB6 and PB7 are ignored.
//
// PortC:
// PC6 and PC7 can not be used.
// The reset pin can be set as PC6, but a Arduino Uno has a normal RESET.
// Just as with PortB, also 6 pins here and the whole PortC may be written.
// Note that the Arduino Nano has analog inputs A6 and A7, but those are
// are not connected to PortC.
//
// PortD:
// All the 8 pins may be used.
// The RX and TX pins are PD0 and PD1, so the Serial port can no longer be used.
//
// See the file "README.md" for (unsafe) tricks.
//
void setup()
{
// set pins as outputs. The PB6, PB7, PC6, PC7 will be ignored for a Arduino Uno.
DDRB = 0xFF;
DDRC = 0xFF;
DDRD = 0xFF;
}
void loop()
{
// Turn the whole ports on and off, randomly
switch( random( 3))
{
case 0:
PORTB = (random( 0, 2) == 1) ? 0xFF : 0x00; // set whole PortB on or off
break;
case 1:
PORTC = (random( 0, 2) == 1) ? 0xFF : 0x00; // set whole PortC on or off
break;
case 2:
PORTD = (random( 0, 2) == 1) ? 0xFF : 0x00; // set whole PortD on or off
break;
}
delay( 40);
}