Skip to content

Commit f4721fc

Browse files
committed
example code for STEMMA analog switch
CircuitPython and Arduino examples for using the STEMMA analog switch
1 parent 270354b commit f4721fc

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
int analogIn = A1;
6+
// in arduino, feather rp2040 pin 5 is pin 7
7+
int digitalOut = 7;
8+
int analogValue = 0;
9+
unsigned long timer = 2000;
10+
unsigned long startTime = millis();
11+
12+
void setup() {
13+
Serial.begin(115200);
14+
pinMode(digitalOut, OUTPUT);
15+
}
16+
17+
// the loop function runs over and over again forever
18+
void loop() {
19+
analogValue = analogRead(analogIn);
20+
Serial.println(analogValue);
21+
if ((millis() - startTime) >= timer) {
22+
digitalWrite(digitalOut, !digitalRead(digitalOut));
23+
startTime = millis();
24+
}
25+
delay(10);
26+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
2+
# SPDX-License-Identifier: MIT
3+
4+
import time
5+
import board
6+
from digitalio import DigitalInOut, Direction
7+
from analogio import AnalogIn
8+
9+
analog_in = AnalogIn(board.A1)
10+
11+
switch = DigitalInOut(board.D5)
12+
switch.direction = Direction.OUTPUT
13+
14+
switch_time = 2
15+
clock = time.monotonic()
16+
while True:
17+
if (time.monotonic() - clock) > switch_time:
18+
switch.value = not switch.value
19+
print(switch.value)
20+
clock = time.monotonic()
21+
print((analog_in.value,))
22+
time.sleep(0.1)

0 commit comments

Comments
 (0)