example code for STEMMA analog switch
CircuitPython and Arduino examples for using the STEMMA analog switch
This commit is contained in:
parent
270354bfba
commit
f4721fcd25
2 changed files with 48 additions and 0 deletions
|
|
@ -0,0 +1,26 @@
|
|||
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
|
||||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
int analogIn = A1;
|
||||
// in arduino, feather rp2040 pin 5 is pin 7
|
||||
int digitalOut = 7;
|
||||
int analogValue = 0;
|
||||
unsigned long timer = 2000;
|
||||
unsigned long startTime = millis();
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
pinMode(digitalOut, OUTPUT);
|
||||
}
|
||||
|
||||
// the loop function runs over and over again forever
|
||||
void loop() {
|
||||
analogValue = analogRead(analogIn);
|
||||
Serial.println(analogValue);
|
||||
if ((millis() - startTime) >= timer) {
|
||||
digitalWrite(digitalOut, !digitalRead(digitalOut));
|
||||
startTime = millis();
|
||||
}
|
||||
delay(10);
|
||||
}
|
||||
22
STEMMA_Analog_Switch_Examples/CircuitPython/code.py
Normal file
22
STEMMA_Analog_Switch_Examples/CircuitPython/code.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import time
|
||||
import board
|
||||
from digitalio import DigitalInOut, Direction
|
||||
from analogio import AnalogIn
|
||||
|
||||
analog_in = AnalogIn(board.A1)
|
||||
|
||||
switch = DigitalInOut(board.D5)
|
||||
switch.direction = Direction.OUTPUT
|
||||
|
||||
switch_time = 2
|
||||
clock = time.monotonic()
|
||||
while True:
|
||||
if (time.monotonic() - clock) > switch_time:
|
||||
switch.value = not switch.value
|
||||
print(switch.value)
|
||||
clock = time.monotonic()
|
||||
print((analog_in.value,))
|
||||
time.sleep(0.1)
|
||||
Loading…
Reference in a new issue