Arduino-GPIO
General Purpose Input/Output (GPIO) library for Arduino
Benchmark.ino
Go to the documentation of this file.
1 #include "GPIO.h"
2 #include "benchmark.h"
3 
4 #include "Software/Serial.h"
8 #define LED_PIN 1
9 #define BUTTON_PIN 2
10 
11 void setup()
12 {
13  Serial.begin(57600);
14  while (!Serial);
15 
16  // Set pin mode; Arduino style
17  pinMode(LED_PIN, OUTPUT);
18  pinMode(BUTTON_PIN, INPUT_PULLUP);
19 
20  // Set pin mode; GPIO style
21  led.output();
22  button.input().pullup();
23 
24  // Calculate baseline
25  BENCHMARK_BASELINE(1000);
26 }
27 
28 void loop()
29 {
30  BENCHMARK("1.1 Arduino core digitalRead", 1000) {
31  bool state = digitalRead(BUTTON_PIN);
32  (void) state;
33  }
34 
35  BENCHMARK("1.2 Arduino core digitalWrite(HIGH)", 1000) {
36  digitalWrite(LED_PIN, HIGH);
37  }
38 
39  BENCHMARK("1.3 Arduino core digitalWrite(LOW)", 1000) {
40  digitalWrite(LED_PIN, LOW);
41  }
42 
43  BENCHMARK("1.4 Arduino core toggle; digitalRead-digitalWrite", 1000) {
44  digitalWrite(LED_PIN, !digitalRead(LED_PIN));
45  }
46 
47  BENCHMARK("1.5 Arduino core toggle; digitalWrite", 1000) {
48  digitalWrite(LED_PIN, HIGH);
49  digitalWrite(LED_PIN, LOW);
50  }
51 
52  BENCHMARK("2.1 GPIO pin value operator", 1000) {
53  bool state = button;
54  (void) state;
55  }
56 
57  BENCHMARK("2.2 GPIO high member function", 1000) {
58  led.high();
59  }
60 
61  BENCHMARK("2.3 GPIO low member function", 1000) {
62  led.low();
63  }
64 
65  BENCHMARK("2.4 GPIO assignment HIGH", 1000) {
66  led = HIGH;
67  }
68 
69  BENCHMARK("2.5 GPIO assignment LOW", 1000) {
70  led = LOW;
71  }
72 
73  BENCHMARK("2.6 GPIO toggle; value and assignment operator", 1000) {
74  led = !led;
75  }
76 
77  BENCHMARK("2.7 GPIO toggle; high and low member functions", 1000) {
78  led.high();
79  led.low();
80  }
81 
82  BENCHMARK("2.8 GPIO toggle; assignment operator, HIGH/LOW", 1000) {
83  led = HIGH;
84  led = LOW;
85  }
86 
87  BENCHMARK("2.9 GPIO toggle member function", 1000) {
88  led.toggle();
89  }
90 
91  Serial.println();
92  delay(2000);
93 }
void begin(uint32_t baudrate)
Definition: Serial.h:50
void setup()
Definition: Benchmark.ino:11
GPIO< BOARD::D2 > button
Definition: Benchmark.ino:7
void high()
Definition: GPIO.h:104
GPIO< PIN > & input()
Definition: GPIO.h:36
#define BUTTON_PIN
Definition: Benchmark.ino:9
void toggle()
Definition: GPIO.h:113
#define BENCHMARK(msg, scale)
Definition: benchmark.h:52
#define BENCHMARK_BASELINE(scale)
Definition: benchmark.h:34
Software::Serial< BOARD::D0 > Serial
Definition: Benchmark.ino:5
void loop()
Definition: Benchmark.ino:28
void output()
Definition: GPIO.h:56
Definition: GPIO.h:31
GPIO< BOARD::D1 > led
Definition: Benchmark.ino:6
void low()
Definition: GPIO.h:95
#define LED_PIN
Definition: Benchmark.ino:8