Skip to content

Commit 38fde3b

Browse files
brentrutannewt
brentru
authored andcommitted
added demos for square and sine, fixed square per comment
1 parent f80005e commit 38fde3b

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

adafruit_waveform/square.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
import array
3232

3333

34-
def square_wave(sample_length = 2):
34+
def square_wave(sample_length=2):
3535
"""Generate a single square wave of sample_length size"""
36-
s = array.array("H", [0] * sample_length)
37-
for i in range(sample_length / 2):
38-
s[i] = 0xFFFF
39-
return s
36+
square = array.array("H", [0] * sample_length)
37+
for i in range(sample_length // 2):
38+
square[i] = 0xFFFF
39+
return square

examples/sine_demo.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""
2+
'sine_demo.py'.
3+
4+
=================================================
5+
toggles the builtin LED using a sine wave
6+
"""
7+
import time
8+
import board
9+
import digitalio
10+
from adafruit_waveform import sine
11+
12+
LED = digitalio.DigitalInOut(board.D13)
13+
LED.switch_to_output()
14+
15+
SINE_SAMPLE = sine.sine_wave(150, 50)
16+
17+
while True:
18+
for i in range(len(SINE_SAMPLE)):
19+
LED.value = i
20+
print(LED.value)
21+
time.sleep(0.50)

examples/square_demo.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
"""
2+
'square_demo.py'.
3+
4+
=================================================
5+
toggles the builtin LED using a square wave
6+
"""
7+
import time
8+
import digitalio
9+
import board
10+
from adafruit_waveform import square
11+
12+
LED = digitalio.DigitalInOut(board.D13)
13+
LED.switch_to_output()
14+
SAMPLE_SQUARE = square.square_wave(2)
15+
16+
while True:
17+
for i in range(len(SAMPLE_SQUARE)):
18+
LED.value = i
19+
print(LED.value)
20+
time.sleep(0.5)

0 commit comments

Comments
 (0)