diff --git a/Close_Encounters_Hat/Close_Encounters_Hat.fzz b/Close_Encounters_Hat/Close_Encounters_Hat.fzz new file mode 100644 index 000000000..1885e1f9a Binary files /dev/null and b/Close_Encounters_Hat/Close_Encounters_Hat.fzz differ diff --git a/Close_Encounters_Hat/Close_Encounters_Hat.ino b/Close_Encounters_Hat/Close_Encounters_Hat.ino new file mode 100644 index 000000000..d8039d59e --- /dev/null +++ b/Close_Encounters_Hat/Close_Encounters_Hat.ino @@ -0,0 +1,128 @@ +/* +Close Encounters hat with 10 neopixels by Leslie Birch for Adafruit Industries. +Notes play with each corresponding light. +Based on code by Becky Stern, Mike Barela and T Main for Adafruit Industries +http://learn.adafruit.com/adafruit-trinket-modded-stuffed-animal/animal-sounds +*/ + +const int speaker = 0; // the number of the speaker +#define PHOTOCELL 1 // cDS photocell on A1 + +// this section is Close Encounters Sounds +#define toneC 1046.50 +#define toneG 1567.98 +#define tonec 2093.00 +#define toned 2349.32 +#define tonee 2637.02 +#define tonep 0 + +#define darkness_min 512 // analog 0-1024 0-512 (light, 513-1023 dark) + +long vel = 20000; + +// This section is NeoPixel Variables + +#include + +#define PIN 1 + +// Parameter 1 = number of pixels in strip +// Parameter 2 = pin number (most are valid) +// Parameter 3 = pixel type flags, add together as needed: +// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs) +// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers) +// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products) +// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2) +//Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, 1, NEO_GRB + NEO_KHZ800); +Adafruit_NeoPixel strip = Adafruit_NeoPixel(10, 1); + + +void setup() { + pinMode(speaker, OUTPUT); + + Serial.println("setup"); + + //This is for Neopixel Setup + strip.begin(); + strip.show(); // Initialize all pixels to 'off' +} + +void loop() +{ + // turn lights and audio on when dark + // less than 50% light on analog pin + if ( analogRead(PHOTOCELL) > darkness_min ) { + + alien(); // Close Encounters Loop + + } + + } + +// 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 32k out of 64k + +# this section is Close Encounters Sounds +toned = 294 +tonee = 330 +tonec = 262 +toneC = 130 +toneg = 392 + +photocell = analogio.AnalogIn(photocell_pin) +pwm = pulseio.PWMOut(speaker_pin, variable_frequency=True, duty_cycle=0) +strip = neopixel.NeoPixel(pixpin, numpix, brightness=.4) + +# Read photocell analog pin and convert voltage to frequency +def beep(tone_freq): + pwm.frequency = tone_freq + pwm.duty_cycle = 32767 # 50% duty cycle + time.sleep(1) # Play for 1 second + pwm.duty_cycle = 0 # Stop playing + +def alien(): + strip[8] = (255, 255, 0) # yellow front + strip[3] = (255, 255, 0) # yellow back + beep(toned) + + time.sleep(.025) + + strip[8] = (0, 0, 0) # clear front + strip[3] = (0, 0, 0) # clear back + + time.sleep(.025) + + strip[7] = (255, 0, 255) # pink front + strip[2] = (255, 0, 255) # pink back + beep(tonee) + + time.sleep(.025) + + strip[7] = (0, 0, 0) # clear front + strip[2] = (0, 0, 0) # clear back + + time.sleep(.025) + + strip[4] = (128, 255, 0) # green front + strip[9] = (128, 255, 0) # green back + beep(tonec) + + time.sleep(.025) + + strip[4] = (0, 0, 0) # clear front + strip[9] = (0, 0, 0) # clear back + + time.sleep(.025) + + strip[5] = (0, 0, 255) # blue front + strip[0] = (0, 0, 255) # blue back + beep(toneC) + + time.sleep(.075) + + strip[5] = (0, 0, 0) # clear front + strip[0] = (0, 0, 0) # clear back + + time.sleep(.1) + + strip[6] = (255, 0, 0) # red front + strip[1] = (255, 0, 0) # red back + beep(toneg) + + time.sleep(.1) + + strip[6] = (0, 0, 0) # clear front + strip[1] = (0, 0, 0) # clear back + + time.sleep(.1) + +# Loop forever... +while True: + + # turn lights and audio on when dark + # (less than 50% light on analog pin) + if ( photocell.value > darkness_min ): + alien() # close Encounters Loop