Patrick Fitzgerald
Published

Computer Logic

Arduino programming language is like mathematics

IntermediateProtip2 hours232

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
10 LEDs Bar Array, Green
10 LEDs Bar Array, Green
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

demo.ino

Arduino
Arduino sketch using mathematics to blink LED
#define reps 3
#define byteLength 8
void setup() { DDRB = 0xFF;}  // all PORTB outputs
void loop()  {
  // shift 1 left shift 128 right
  for (int i=0; i < reps;i++)
  {
  for (int j=0; j < byteLength ;j++) { PORTB = (1 << j); delay(200);}
  for (int j=0; j < byteLength ;j++) { PORTB = (128 >> j); delay(200);}
  }
  // Bitwise Not flips the bits
  PORTB = 0b01010101;  // inital value
  for (int i=0; i < reps;i++) {  PORTB = ~PORTB;   delay(800); }
  // PORTB is a software variable and a hardware circuit
  while (PORTB < 0xFF) { PORTB++, delay(50); }
}

Credits

Patrick Fitzgerald
124 projects • 50 followers

Comments