Skip to content

Commit ec6d564

Browse files
committed
Merge branch 'refs/heads/main' into kareltherobot
2 parents a554b04 + c16c5b8 commit ec6d564

File tree

3 files changed

+118
-0
lines changed

3 files changed

+118
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
2+
//
3+
// SPDX-License-Identifier: MIT
4+
5+
const int DIR = 5;
6+
const int STEP = 6;
7+
const int microMode = 16; // microstep mode, default is 1/16 so 16; ex: 1/4 would be 4
8+
// full rotation * microstep divider
9+
const int steps = 200 * microMode;
10+
11+
void setup()
12+
{
13+
// setup step and dir pins as outputs
14+
pinMode(STEP, OUTPUT);
15+
pinMode(DIR, OUTPUT);
16+
}
17+
18+
void loop()
19+
{
20+
// change direction every loop
21+
digitalWrite(DIR, !digitalRead(DIR));
22+
// toggle STEP to move
23+
for(int x = 0; x < steps; x++)
24+
{
25+
digitalWrite(STEP, HIGH);
26+
delay(2);
27+
digitalWrite(STEP, LOW);
28+
delay(2);
29+
}
30+
delay(1000); // 1 second delay
31+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import time
6+
import board
7+
from digitalio import DigitalInOut, Direction
8+
9+
# direction and step pins as outputs
10+
DIR = DigitalInOut(board.D5)
11+
DIR.direction = Direction.OUTPUT
12+
STEP = DigitalInOut(board.D6)
13+
STEP.direction = Direction.OUTPUT
14+
15+
# microstep mode, default is 1/16 so 16
16+
# another ex: 1/4 microstep would be 4
17+
microMode = 16
18+
# full rotation multiplied by the microstep divider
19+
steps = 200 * microMode
20+
21+
while True:
22+
# change direction every loop
23+
DIR.value = not DIR.value
24+
# toggle STEP pin to move the motor
25+
for i in range(steps):
26+
STEP.value = True
27+
time.sleep(0.001)
28+
STEP.value = False
29+
time.sleep(0.001)
30+
print("rotated! now reverse")
31+
# 1 second delay before starting again
32+
time.sleep(1)

IoT_Christmas_Lights_Switch/code.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
import time
6+
import os
7+
import ssl
8+
import wifi
9+
import socketpool
10+
import microcontroller
11+
import board
12+
import digitalio
13+
import adafruit_requests
14+
from adafruit_io.adafruit_io import IO_HTTP, AdafruitIO_RequestError
15+
16+
aio_username = os.getenv("ADAFRUIT_AIO_USERNAME")
17+
aio_key = os.getenv("ADAFRUIT_AIO_KEY")
18+
19+
# buttons
20+
button = digitalio.DigitalInOut(board.D5)
21+
button.direction = digitalio.Direction.INPUT
22+
button.pull = digitalio.Pull.UP
23+
button_state = False
24+
25+
lights_on = False
26+
27+
print()
28+
print("Connecting to WiFi...")
29+
# connect to your SSID
30+
wifi.radio.connect(os.getenv('CIRCUITPY_WIFI_SSID'), os.getenv('CIRCUITPY_WIFI_PASSWORD'))
31+
print("Connected to WiFi!")
32+
33+
pool = socketpool.SocketPool(wifi.radio)
34+
requests = adafruit_requests.Session(pool, ssl.create_default_context())
35+
36+
io = IO_HTTP(aio_username, aio_key, requests)
37+
38+
try:
39+
feed_lights = io.get_feed("lights")
40+
except AdafruitIO_RequestError:
41+
feed_lights = io.create_new_feed("lights")
42+
43+
while True:
44+
try:
45+
if not button.value and button_state:
46+
button_state = False
47+
if button.value and not button_state:
48+
print("pressed")
49+
lights_on = not lights_on
50+
io.send_data(feed_lights["key"], int(lights_on))
51+
button_state = True
52+
except Exception as error: # pylint: disable=broad-except
53+
print(error)
54+
time.sleep(5)
55+
microcontroller.reset()

0 commit comments

Comments
 (0)