Skip to content

Commit 76cd05b

Browse files
authored
Merge pull request #2764 from adafruit/tcrt1000
adding example code for TCRT1000
2 parents e107195 + 8f7b5af commit 76cd05b

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

STEMMA_TCRT1000/CircuitPython/code.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# SPDX-FileCopyrightText: 2023 Liz Clark for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import time
6+
import board
7+
from digitalio import DigitalInOut, Direction, Pull
8+
9+
ir = DigitalInOut(board.D5)
10+
ir.direction = Direction.INPUT
11+
ir.pull = Pull.UP
12+
13+
while True:
14+
if not ir.value:
15+
print("object detected!")
16+
else:
17+
print("waiting for object...")
18+
time.sleep(0.01)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
void setup() {
6+
//start serial connection
7+
Serial.begin(115200);
8+
pinMode(5, INPUT_PULLUP);
9+
10+
}
11+
12+
void loop() {
13+
int sensorVal = digitalRead(5);
14+
15+
if (sensorVal == LOW) {
16+
Serial.println("object detected!");
17+
} else {
18+
Serial.println("waiting for object..");
19+
}
20+
delay(200);
21+
}

0 commit comments

Comments
 (0)