Merge pull request #2764 from adafruit/tcrt1000
adding example code for TCRT1000
This commit is contained in:
commit
76cd05be8f
2 changed files with 39 additions and 0 deletions
18
STEMMA_TCRT1000/CircuitPython/code.py
Normal file
18
STEMMA_TCRT1000/CircuitPython/code.py
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
# SPDX-FileCopyrightText: 2023 Liz Clark for Adafruit Industries
|
||||||
|
#
|
||||||
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
import time
|
||||||
|
import board
|
||||||
|
from digitalio import DigitalInOut, Direction, Pull
|
||||||
|
|
||||||
|
ir = DigitalInOut(board.D5)
|
||||||
|
ir.direction = Direction.INPUT
|
||||||
|
ir.pull = Pull.UP
|
||||||
|
|
||||||
|
while True:
|
||||||
|
if not ir.value:
|
||||||
|
print("object detected!")
|
||||||
|
else:
|
||||||
|
print("waiting for object...")
|
||||||
|
time.sleep(0.01)
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
//start serial connection
|
||||||
|
Serial.begin(115200);
|
||||||
|
pinMode(5, INPUT_PULLUP);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
int sensorVal = digitalRead(5);
|
||||||
|
|
||||||
|
if (sensorVal == LOW) {
|
||||||
|
Serial.println("object detected!");
|
||||||
|
} else {
|
||||||
|
Serial.println("waiting for object..");
|
||||||
|
}
|
||||||
|
delay(200);
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue