File tree Expand file tree Collapse file tree 3 files changed +47
-0
lines changed
STEMMA_Analog_Switch_Examples
Arduino_Analog_Switch_Example Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ // SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
2
+ //
3
+ // SPDX-License-Identifier: MIT
4
+
5
+ int analogIn = A1;
6
+ int digitalOut = 5 ;
7
+ int analogValue = 0 ;
8
+ unsigned long timer = 2000 ;
9
+ unsigned long startTime = millis();
10
+
11
+ void setup () {
12
+ Serial.begin (115200 );
13
+ pinMode (digitalOut, OUTPUT);
14
+ }
15
+
16
+ // the loop function runs over and over again forever
17
+ void loop () {
18
+ analogValue = analogRead (analogIn);
19
+ Serial.println (analogValue);
20
+ if ((millis () - startTime) >= timer) {
21
+ digitalWrite (digitalOut, !digitalRead (digitalOut));
22
+ startTime = millis ();
23
+ }
24
+ delay (10 );
25
+ }
Original file line number Diff line number Diff line change
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 )
You can’t perform that action at this time.
0 commit comments