Hobby Electronics Projects & More

Arduino Nano test circuit.

Arduino Blink LED Tutorial

by Lewis Loflin

The Arduino test program 'blink' uses 580 bytes. The video discusses alternative programming methods to make better use of resources.

ATmega168 pin connections



/*
DDR - data direction register
0 = INPUT; 1 = OUTPUT

PORTB - port B data register
0 = 0V; 1 = 5V

0b00000000
PB7  to  PB0

PB0 = DP8
PB1 = DP9
PB2 = DP10
PB3 = DP11
PB4 = DP12
PB5 = DP13
PB6 & PB7 = crystal
*/

#define L1 9 // DP9 or PB1

// empty setup and loop 450 bytes

void setup() {
  // DDRB = DDRB | 0b00000010;  // 2 bytes
  // DDRB = 0b00000010; // 4 bytes
  // DDRB = 2; // same as above 4 bytes
  // pinMode(L1, OUTPUT); // 180 bytes
  // OUTPUT = 1, INPUT = 0
  // pinMode(L1, 1); // 180 bytes
}

byte num = 0; // 8-bit unsigned 0-255

void loop() {

  //   num = num ^ 1; // 12 bytes
  //   num = !num; // 14 bytes
  //   PORTB = PORTB ^ 0b00000010; // 8 bytes
  //   PORTB = PORTB ^ 2; // 8 bytes  

  //   read IO register directly  
  //   num = digitalRead(L1);
  //   num = !num
  //   num = digitalRead(L1) ^ 1;
  //   num = !digitalRead(L1);
  
  //   digitalWrite(L1, num); // 268 bytes once
  //   digitalWrite(L1, num = !num); // 278 bytes
  //   delay(500); // 162 bytes once
  //   myDelay(500); // 64 bytes once

  //   digitalWrite(L1, num); // 10 bytes
  //   delay(500); // 12 bytes
  //   myDelay(500); // 8 bytes

}

//  x * 1mS delay 64 bytes
// unsigned int 2 bytes
// 2^16 - 1 = 65,535
// unsigned long 4 bytes
// 2^32 - 1 = 4,294,967,295

// milliSec. delay 64 bytes
void myDelay(unsigned int x)   {
  for (unsigned int y = 0; y <= x; y++)   {
    delayMicroseconds(1000);
  }

}



Videos:
My YouTube Videos on Electronics
Introduction to the Arduino Microcontroller
Part 1: Programming Arduino Output
Part 2: Programming Arduino Input
Part 3: Arduino Analog to Digital Conversion
Part 4: Using Arduino Pulse-Width-Modulation
Repost Arduino AC Power Control