Page 3 of 16
Article Index
void setup() {
pinMode(2, OUTPUT);
}
void loop() {
digitalWrite(2, HIGH);
digitalWrite(2, LOW);
}
Page 49
void setup() {
pinMode(2, OUTPUT);
}
volatile int waste;
void loop() {
digitalWrite(2, HIGH);
for(waste=0;waste<6;waste++);
digitalWrite(2, LOW);
}
Page 50
void setup() {
pinMode(2, OUTPUT);
}
void loop() {
digitalWrite(2, HIGH);
delayMicroseconds(1);
digitalWrite(2, LOW);
delayMicroseconds(1);
}
Page 50
void setup() {
pinMode(2, OUTPUT);
}
volatile int i = 0;
int n;
void loop() {
for (n = 1; n < 11; n++) {
digitalWrite(2, HIGH);
for (i = 0; i < n; i++) {}
digitalWrite(2, LOW);
for (i = 0; i < n; i++) {}
}
}
Page 52
unsigned long tick_us(unsigned long offset) {
return micros() + offset;
}
void delay_until(unsigned long t) {
do {
} while (t > micros());
}
void setup() {
pinMode(2, OUTPUT);
}
volatile int i = 0;
int n = 2;
unsigned long width = 1000;
unsigned long t;
void loop() {
t = tick_us(width);
digitalWrite(2, HIGH);
for (i = 0; i < n; i++) {}
delay_until(t);
t = tick_us(width);
digitalWrite(2, LOW);
for (i = 0; i < n; i++) {}
delay_until(t);
}
Page 54
void setup() {
pinMode(2, OUTPUT);
pinMode(4, OUTPUT);
}
void loop() {
digitalWrite(2, HIGH);
digitalWrite(4, LOW);
digitalWrite(2, LOW);
digitalWrite(4, HIGH);
}
Page 56
void gpio_set(int32_t value, int32_t mask) {
int32_t *OutAdd = (int32_t *)GPIO_OUT_REG;
*OutAdd = (*OutAdd & ~mask) | (value & mask);
}
void setup() {
pinMode(2, OUTPUT);
pinMode(4, OUTPUT);
}
volatile int i = 0;
int32_t mask = 1 << 2 | 1 << 4;
int32_t value1 = 0 << 2 | 1 << 4;
int32_t value2 = 1 << 2 | 0 << 4;
void loop() {
gpio_set(value1, mask);
for (i = 0; i < 5; i++) {}
gpio_set(value2, mask);
}