File tree Expand file tree Collapse file tree 2 files changed +48
-0
lines changed
STEMMA_Analog_Switch_Examples
Arduino_Analog_Switch_Example Expand file tree Collapse file tree 2 files changed +48
-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
+ // 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
+ }
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