From a9e6fd98d190f7ed535534e8c43b1d4d1998046c Mon Sep 17 00:00:00 2001 From: Phillip Burgess Date: Sat, 30 Sep 2017 19:55:22 -0700 Subject: [PATCH 1/2] Add 4 Gemma projects (empty, WIP) --- LED_Masquerade_Masks/LED_Masquerade_Masks.ino | 0 LED_Masquerade_Masks/LED_Masquerade_Masks.py | 0 Light_Activated_Pixel_Heart/Light_Activated_Pixel_Heart.ino | 0 Light_Activated_Pixel_Heart/Light_Activated_Pixel_Heart.py | 0 .../Sound_Reactive_NeoPixel_Peace_Pendant.ino | 0 .../Sound_Reactive_NeoPixel_Peace_Pendant.py | 0 Trinket_Gemma_Mini_Theramin/Trinket_Gemma_Mini_Theramin.ino | 0 Trinket_Gemma_Mini_Theramin/Trinket_Gemma_Mini_Theramin.py | 0 8 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 LED_Masquerade_Masks/LED_Masquerade_Masks.ino create mode 100644 LED_Masquerade_Masks/LED_Masquerade_Masks.py create mode 100644 Light_Activated_Pixel_Heart/Light_Activated_Pixel_Heart.ino create mode 100644 Light_Activated_Pixel_Heart/Light_Activated_Pixel_Heart.py create mode 100644 Sound_Reactive_NeoPixel_Peace_Pendant/Sound_Reactive_NeoPixel_Peace_Pendant.ino create mode 100644 Sound_Reactive_NeoPixel_Peace_Pendant/Sound_Reactive_NeoPixel_Peace_Pendant.py create mode 100644 Trinket_Gemma_Mini_Theramin/Trinket_Gemma_Mini_Theramin.ino create mode 100644 Trinket_Gemma_Mini_Theramin/Trinket_Gemma_Mini_Theramin.py diff --git a/LED_Masquerade_Masks/LED_Masquerade_Masks.ino b/LED_Masquerade_Masks/LED_Masquerade_Masks.ino new file mode 100644 index 000000000..e69de29bb diff --git a/LED_Masquerade_Masks/LED_Masquerade_Masks.py b/LED_Masquerade_Masks/LED_Masquerade_Masks.py new file mode 100644 index 000000000..e69de29bb diff --git a/Light_Activated_Pixel_Heart/Light_Activated_Pixel_Heart.ino b/Light_Activated_Pixel_Heart/Light_Activated_Pixel_Heart.ino new file mode 100644 index 000000000..e69de29bb diff --git a/Light_Activated_Pixel_Heart/Light_Activated_Pixel_Heart.py b/Light_Activated_Pixel_Heart/Light_Activated_Pixel_Heart.py new file mode 100644 index 000000000..e69de29bb diff --git a/Sound_Reactive_NeoPixel_Peace_Pendant/Sound_Reactive_NeoPixel_Peace_Pendant.ino b/Sound_Reactive_NeoPixel_Peace_Pendant/Sound_Reactive_NeoPixel_Peace_Pendant.ino new file mode 100644 index 000000000..e69de29bb diff --git a/Sound_Reactive_NeoPixel_Peace_Pendant/Sound_Reactive_NeoPixel_Peace_Pendant.py b/Sound_Reactive_NeoPixel_Peace_Pendant/Sound_Reactive_NeoPixel_Peace_Pendant.py new file mode 100644 index 000000000..e69de29bb diff --git a/Trinket_Gemma_Mini_Theramin/Trinket_Gemma_Mini_Theramin.ino b/Trinket_Gemma_Mini_Theramin/Trinket_Gemma_Mini_Theramin.ino new file mode 100644 index 000000000..e69de29bb diff --git a/Trinket_Gemma_Mini_Theramin/Trinket_Gemma_Mini_Theramin.py b/Trinket_Gemma_Mini_Theramin/Trinket_Gemma_Mini_Theramin.py new file mode 100644 index 000000000..e69de29bb From 5a7a1f5b85650e3fdcbe098c9f6f0d8abb9f8579 Mon Sep 17 00:00:00 2001 From: Phillip Burgess Date: Sun, 1 Oct 2017 16:53:24 -0700 Subject: [PATCH 2/2] Add Trinket theremin code --- .../Trinket_Gemma_Mini_Theramin.ino | 48 +++++++++++++++++++ .../Trinket_Gemma_Mini_Theramin.py | 33 +++++++++++++ 2 files changed, 81 insertions(+) diff --git a/Trinket_Gemma_Mini_Theramin/Trinket_Gemma_Mini_Theramin.ino b/Trinket_Gemma_Mini_Theramin/Trinket_Gemma_Mini_Theramin.ino index e69de29bb..9e56d99e8 100644 --- a/Trinket_Gemma_Mini_Theramin/Trinket_Gemma_Mini_Theramin.ino +++ b/Trinket_Gemma_Mini_Theramin/Trinket_Gemma_Mini_Theramin.ino @@ -0,0 +1,48 @@ +/* Adafruit Trinket/Gemma Example: Simple Theramin + + Read the voltage from a Cadmium Sulfide (CdS) photocell voltage + divider and output a corresponding tone to a piezo buzzer + + Wiring: Photocell voltage divider center wire to GPIO #2 + (analog 1) and output tone to GPIO #0 (digital 0) + + Note: The Arduino tone library does not work for the ATTiny85 on the + Trinket and Gemma. The beep function below is similar. The beep + code is adapted from Dr. Leah Buechley at + http://web.media.mit.edu/~leah/LilyPad/07_sound_code.html +*/ + +#define SPEAKER 0 // Speaker connected to this DIGITAL pin # +#define PHOTOCELL 1 // CdS photocell connected to this ANALOG pin # +#define SCALE 2.0 // You can change this to change the tone scale + +void setup() { + // Set SPEAKER pin to output to drive the piezo buzzer (important) + pinMode(SPEAKER, OUTPUT); +} + +void loop() { + // Read PHOTOCELL analog pin for the current CdS divider voltage + int reading = analogRead(PHOTOCELL); + // Change the voltage to a frequency. You can change the values + // to scale your frequency range. + int freq = 220 + (int)(reading * SCALE); + // Output the tone to SPEAKER pin. You can change the '400' + // to different times (in milliseconds). + beep(SPEAKER, freq, 400); + delay(50); // Delay a bit between notes (also adjustable to taste) +} + +// The sound-producing function +void beep (unsigned char speakerPin, int frequencyInHertz, long timeInMilliseconds) +{ // http://web.media.mit.edu/~leah/LilyPad/07_sound_code.html + int x; + long delayAmount = (long)(1000000 / frequencyInHertz); + long loopTime = (long)((timeInMilliseconds * 1000) / (delayAmount * 2)); + for (x = 0; x < loopTime; x++) { + digitalWrite(speakerPin, HIGH); + delayMicroseconds(delayAmount); + digitalWrite(speakerPin, LOW); + delayMicroseconds(delayAmount); + } +} diff --git a/Trinket_Gemma_Mini_Theramin/Trinket_Gemma_Mini_Theramin.py b/Trinket_Gemma_Mini_Theramin/Trinket_Gemma_Mini_Theramin.py index e69de29bb..77432bd23 100644 --- a/Trinket_Gemma_Mini_Theramin/Trinket_Gemma_Mini_Theramin.py +++ b/Trinket_Gemma_Mini_Theramin/Trinket_Gemma_Mini_Theramin.py @@ -0,0 +1,33 @@ +# Adafruit Trinket/Gemma Example: Simple Theramin +# Read the voltage from a Cadmium Sulfide (CdS) photocell voltage +# divider and output a corresponding tone to a piezo buzzer +# +# Photocell voltage divider center wire to GPIO #2 (analog 1) +# and output tone to GPIO #0 (digital 0) + +import board +import analogio +import digitalio +import time + +speaker_pin = board.D0 # Speaker is connected to this DIGITAL pin +photocell_pin = board.A1 # CdS photocell connected to this ANALOG pin +scale = 0.03 # Change this to adjust tone scale + +readpin = analogio.AnalogIn(photocell_pin) +writepin = digitalio.DigitalInOut(speaker_pin) +writepin.direction = digitalio.Direction.OUTPUT + +while True: # Loop forever... + # Read photocell analog pin and convert voltage to frequency + freq_hz = 220 + readpin.value * scale + + delay_amount = 0.5 / freq_hz # 1/2 Frequency + note_start = time.monotonic() # Time when note started + while time.monotonic() - note_start < 0.4: # For 400 milliseconds... + writepin.value = True # Set pin high + time.sleep(delay_amount) # Wait for 1/2 of note frequency + writepin.value = False # Set pin low + time.sleep(delay_amount) # Wait for other 1/2 of note freq. + + time.sleep(0.05) # Delay 50 ms between notes (also adjustable)