Skip to content

Commit

Permalink
Merge branch 'main' of github.com:adafruit/Adafruit_Learning_System_G…
Browse files Browse the repository at this point in the history
…uides
  • Loading branch information
ladyada committed Oct 17, 2023
2 parents a56d5d5 + 3df559e commit 956fa2c
Show file tree
Hide file tree
Showing 11 changed files with 306 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@

uint8_t i=0;

uint8_t red_out = RED_LED;
uint8_t green_out = GREEN_LED;
uint8_t blue_out = BLUE_LED;

void setup() {
Serial.begin(115200);
Serial.println("\nProp-Maker Wing: LED Example");
Expand All @@ -73,21 +77,32 @@ void setup() {

// Set up the LED Pins
#if defined(ESP32) // and ESP32-S2!
ledcSetup(RED_LED, 5000, 8);
ledcAttachPin(RED_PIN, RED_LED);
ledcSetup(GREEN_LED, 5000, 8);
ledcAttachPin(GREEN_PIN, GREEN_LED);
ledcSetup(BLUE_LED, 5000, 8);
ledcAttachPin(BLUE_PIN, BLUE_LED);
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 1)
// newer LEDC API, use pins instead of channel
red_out = RED_PIN;
green_out = GREEN_PIN;
blue_out = BLUE_PIN;
ledcAttach(RED_PIN, 5000, 8);
ledcAttach(GREEN_PIN, 5000, 8);
ledcAttach(BLUE_PIN, 5000, 8);
#else
// older LEDC API, use channel, attach pin to channel
ledcSetup(RED_LED, 5000, 8);
ledcAttachPin(RED_PIN, RED_LED);
ledcSetup(GREEN_LED, 5000, 8);
ledcAttachPin(GREEN_PIN, GREEN_LED);
ledcSetup(BLUE_LED, 5000, 8);
ledcAttachPin(BLUE_PIN, BLUE_LED);
#endif
#else
pinMode(RED_LED, OUTPUT);
pinMode(GREEN_LED, OUTPUT);
pinMode(BLUE_LED, OUTPUT);
pinMode(red_out, OUTPUT);
pinMode(green_out, OUTPUT);
pinMode(blue_out, OUTPUT);
#endif

analogWrite(RED_LED, 0);
analogWrite(GREEN_LED, 0);
analogWrite(BLUE_LED, 0);
analogWrite(red_out, 0);
analogWrite(green_out, 0);
analogWrite(blue_out, 0);
}

uint32_t Color(uint8_t r, uint8_t g, uint8_t b) {
Expand Down Expand Up @@ -119,8 +134,8 @@ void loop()
digitalWrite(POWER_PIN, HIGH);

// write colors to the 3W LED
analogWrite(RED_LED, red);
analogWrite(GREEN_LED, green);
analogWrite(BLUE_LED, blue);
analogWrite(red_out, red);
analogWrite(green_out, green);
analogWrite(blue_out, blue);
delay(2);
}
}
179 changes: 179 additions & 0 deletions Faz_Wrench/code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
# SPDX-FileCopyrightText: Copyright (c) 2023 Liz Clark for Adafruit Industries
#
# SPDX-License-Identifier: MIT

import os
import random
import board
import audiocore
import audiobusio
import audiomixer
from digitalio import DigitalInOut, Direction
import neopixel
from adafruit_ticks import ticks_ms, ticks_add, ticks_diff
from adafruit_led_animation.animation.pulse import Pulse
from adafruit_led_animation.color import RED, GREEN
import adafruit_character_lcd.character_lcd_i2c as character_lcd
import adafruit_lis3dh
from adafruit_seesaw.seesaw import Seesaw
from adafruit_seesaw.rotaryio import IncrementalEncoder
import keypad

puzzle_time = 5 # seconds

lcd_columns = 16
lcd_rows = 2

# enable external power pin
# provides power to the external components
external_power = DigitalInOut(board.EXTERNAL_POWER)
external_power.direction = Direction.OUTPUT
external_power.value = True

i2c = board.I2C()

int1 = DigitalInOut(board.ACCELEROMETER_INTERRUPT)
lis3dh = adafruit_lis3dh.LIS3DH_I2C(i2c, int1=int1)
lis3dh.range = adafruit_lis3dh.RANGE_2_G

ss_enc0 = Seesaw(i2c, addr=0x36)
enc0 = IncrementalEncoder(ss_enc0)

button = keypad.Keys((board.EXTERNAL_BUTTON, board.D13,), value_when_pressed=False, pull=True)

lcd = character_lcd.Character_LCD_I2C(i2c, lcd_columns, lcd_rows)
lcd.backlight = True

puzzle_msgs = ["UNLOCK\nDOOR", "DOOR\nUNLOCKED", "UNLOCKING"]

wavs = []
for filename in os.listdir('/faz_sounds'):
if filename.lower().endswith('.wav') and not filename.startswith('.'):
wavs.append("/faz_sounds/"+filename)
wavs.sort()
print(wavs)

audio = audiobusio.I2SOut(board.I2S_BIT_CLOCK, board.I2S_WORD_SELECT, board.I2S_DATA)
mixer = audiomixer.Mixer(voice_count=1, sample_rate=22050, channel_count=1,
bits_per_sample=16, samples_signed=True, buffer_size=32768)
volume = 0.5
mixer.voice[0].level = volume
audio.play(mixer)
wav_length = len(wavs) - 1

def open_audio(num):
n = wavs[num]
f = open(n, "rb")
w = audiocore.WaveFile(f)
return w

PIXEL_PIN = board.EXTERNAL_NEOPIXELS
BRIGHTNESS = 0.3
NUM_PIXELS = 8

PIXELS = neopixel.NeoPixel(PIXEL_PIN, NUM_PIXELS, auto_write=True)
pulse = Pulse(PIXELS, speed=0.001, color=RED, period=3)

puzzle_clock = ticks_ms()
puzzle_time = puzzle_time * 1000

puzzle = False
wave = open_audio(0)
pos0 = volume
last_pos0 = pos0
node_num = 0

def normalize(val, min_v, max_v):
return max(min(max_v, val), min_v)

def puzzle_string(length):
_string = ""
for _ in range(length/2):
b = random.randint(0, 1)
if b == 0:
r = chr(random.randint(ord('A'), ord('Z')))
else:
r = str(random.randint(0, 9))
_string += r
_string += "\n"
for _ in range(length/2):
b = random.randint(0, 1)
if b == 0:
r = chr(random.randint(ord('A'), ord('Z')))
else:
r = str(random.randint(0, 9))
_string += r
lcd.message = _string
return _string

while True:
event = button.events.get()
if event and event.pressed:
number = event.key_number
if number == 0 and not puzzle:
pulse.fill(GREEN)
puzzle = True
lcd.clear()
lcd.message = puzzle_msgs[2]
wave = open_audio(1)
mixer.voice[0].play(wave)
while mixer.playing:
pass
puzzle_clock = ticks_add(ticks_ms(), puzzle_time)
if number == 1:
lcd.clear()
node_num = (node_num + 1) % 5
print(node_num)

if puzzle:
x, y, z = [
value / adafruit_lis3dh.STANDARD_GRAVITY for value in lis3dh.acceleration
]
puzzle_string(lcd_columns*lcd_rows)
if z > 0:
wave = open_audio(2)
print("playing up")
pulse.fill(GREEN)
else:
wave = open_audio(3)
print("playing down")
pulse.fill(RED)
mixer.voice[0].play(wave)
while mixer.playing:
puzzle_string(lcd_columns*lcd_rows)
x, y, z = [
value / adafruit_lis3dh.STANDARD_GRAVITY for value in lis3dh.acceleration
]
if z > 0:
pulse.fill(GREEN)
else:
pulse.fill(RED)
if ticks_diff(ticks_ms(), puzzle_clock) >= puzzle_time:
lcd.clear()
puzzle = False
lcd.message = puzzle_msgs[1]
wave = open_audio(4)
mixer.voice[0].play(wave)
while mixer.playing:
pass
print("puzzle done")
wave = open_audio(0)
lcd.clear()
pulse.fill(RED)

if not puzzle:
pulse.animate()
mixer.voice[0].play(wave, loop=True)
if node_num > 3:
lcd.message = "SECURITY\nBREACHED"
else:
lcd.message = f"DEACTIVATED:\n{node_num} of 4"
pos0 = -enc0.position
if pos0 != last_pos0:
if pos0 > last_pos0:
volume = volume + 0.1
else:
volume = volume - 0.1
volume = normalize(volume, 0.0, 1.0)
mixer.voice[0].level = volume
last_pos0 = pos0
Binary file added Faz_Wrench/faz_sounds/0_idle.wav
Binary file not shown.
Binary file added Faz_Wrench/faz_sounds/1_start.wav
Binary file not shown.
Binary file added Faz_Wrench/faz_sounds/2_puzzle-up.wav
Binary file not shown.
Binary file added Faz_Wrench/faz_sounds/3_puzzle-down.wav
Binary file not shown.
Binary file added Faz_Wrench/faz_sounds/4_unlocked.wav
Binary file not shown.
17 changes: 12 additions & 5 deletions FunHouse_Arduino_Demos/rainbow/rainbow.ino
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,31 @@ uint8_t LED_dutycycle = 0;

void setup() {
Serial.begin(115200);

pinMode(LED_BUILTIN, OUTPUT);


#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 1)
ledcAttach(LED_BUILTIN, 5000, 8);
#else
ledcSetup(0, 5000, 8);
ledcAttachPin(LED_BUILTIN, 0);

#endif

pixels.begin(); // Initialize pins for output
pixels.show(); // Turn all LEDs off ASAP
pixels.setBrightness(20);
}



void loop() {
Serial.println("Hello!");

// pulse red LED
#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 1, 1)
ledcWrite(LED_BUILTIN, LED_dutycycle++);
#else
ledcWrite(0, LED_dutycycle++);
#endif

// rainbow dotstars
for (int i=0; i<pixels.numPixels(); i++) { // For each pixel in strip...
Expand All @@ -54,4 +61,4 @@ void rainbow(int wait) {
pixels.show(); // Update strip with new contents
delay(wait); // Pause for a moment
}
}
}
Loading

0 comments on commit 956fa2c

Please sign in to comment.