Skip to content

Commit 589da6f

Browse files
committed
Clean up of examples
1 parent d012f86 commit 589da6f

File tree

1 file changed

+40
-18
lines changed

1 file changed

+40
-18
lines changed

libraries/CoreTesting/examples/Example4_TestAllGPIOs/Example4_TestAllGPIOs.ino

Lines changed: 40 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,61 @@
66
License: MIT. See license file for more information but you can
77
basically do whatever you want with this code.
88
9-
This blinks a given IO pin to verify we have digitalWrite
10-
control of every pin.
11-
9+
This blinks alternating pins to verify we have digitalWrite
10+
control of every pin (and no shorts between pins). Useful for initial hardware testing but
11+
otherwise a pretty boring sketch.
12+
1213
Feel like supporting open source hardware?
1314
Buy a board from SparkFun!
1415
SparkFun Edge: https://www.sparkfun.com/products/15170
1516
1617
Hardware Connections:
17-
Connect an Edge via FTDI programmer
18+
Connect an Edge via serial programmer
1819
Upload code
1920
Verify GPIOs are going high/low every 2 seconds
20-
*/
21+
*/
2122

22-
#define testPin 33
23-
24-
#define LED 5 //On board LED is on pin 5
23+
byte pinsToToggle = 0;
2524

2625
void setup() {
27-
Serial.begin(115200);
28-
Serial.println("SparkFun Arduino Apollo3");
26+
Serial.begin(9600);
27+
28+
#ifdef ARDUINO_AM_AP3_SFE_BB_ARTEMIS
29+
Serial.println("SparkFun BlackBoard Artemis");
30+
pinsToToggle = 30;
31+
#elif AM_AP3_SFE_BB_ARTEMIS_NANO
32+
Serial.println("SparkFun BlackBoard Artemis Nano");
33+
pinsToToggle = 20;
34+
#elif AM_AP3_SFE_BB_ARTEMIS_MEGA
35+
Serial.println("SparkFun BlackBoard Artemis Mega");
36+
pinsToToggle = 50;
37+
#else
38+
Serial.println("Unknown board.");
39+
pinsToToggle = 10;
40+
#endif
2941

30-
pinMode(testPin, OUTPUT);
31-
pinMode(LED, OUTPUT);
42+
Serial.printf("Toggling %d pins\n\r", pinsToToggle); //My goodness it's nice to have printf again
43+
44+
Serial.println("pinMode will override the serial configuration so no more printing...");
45+
46+
for(int x = 0 ; x < pinsToToggle ; x++)
47+
{
48+
pinMode(x, OUTPUT);
49+
}
3250
}
3351

3452
void loop() {
35-
Serial.println("Toggle");
36-
37-
digitalWrite(testPin, LOW);
38-
digitalWrite(LED, LOW);
53+
for(int x = 0 ; x < pinsToToggle ; x++)
54+
{
55+
if(x % 2 == 0) digitalWrite(x, LOW);
56+
else digitalWrite(x, HIGH);
57+
}
3958
delay(2000);
4059

41-
digitalWrite(testPin, HIGH);
42-
digitalWrite(LED, HIGH);
60+
for(int x = 0 ; x < pinsToToggle ; x++)
61+
{
62+
if(x % 2 == 0) digitalWrite(x, HIGH);
63+
else digitalWrite(x, LOW);
64+
}
4365
delay(2000);
4466
}

0 commit comments

Comments
 (0)