Skip to content

Commit 864ba47

Browse files
committed
Add analogRead example
1 parent c65bf9f commit 864ba47

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

examples/analogRead/analogRead.ino

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
Breakout Carrier - analogRead
3+
4+
The sketch shows how to use analog inputs of the Breakout Carrier.
5+
6+
The circuit:
7+
- Portenta H7
8+
- BreakOut Carrier
9+
10+
This example code is in the public domain.
11+
*/
12+
#include "PortentaBreakoutCarrier.h"
13+
14+
const byte ANALOG_PIN_NUMBER = 8;
15+
const int ANALOG_RESOLUTION = 16;
16+
17+
// The access to each analog input is made using the peripheral silk name.
18+
breakoutPin analogPin[] = {ANALOG_A0, ANALOG_A1, ANALOG_A2, ANALOG_A3,
19+
ANALOG_A4, ANALOG_A5, ANALOG_A6, ANALOG_A7};
20+
21+
void setup() {
22+
Serial.begin(9600);
23+
while (!Serial);
24+
25+
// Max analog resolution is 16bits
26+
Breakout.analogReadResolution(ANALOG_RESOLUTION);
27+
}
28+
29+
void loop() {
30+
// Loop through all the available inputs and print input value
31+
for(int i = 0; i < ANALOG_PIN_NUMBER; i++) {
32+
int w = Breakout.analogRead(analogPin[i]);
33+
Serial.print("A");
34+
Serial.print(i);
35+
Serial.print(": ");
36+
Serial.println(w);
37+
38+
delay(1000);
39+
}
40+
}

0 commit comments

Comments
 (0)